* Which Category is your question related to? *
Cognito, AWS AppSync, AppsyncSDK
* What AWS Services are you utilizing? *
Cognito, AWS AppSync
* Provide additional details e.g. code snippets *
I', using Cognito Userpool. In my case our site's access 70% private query (it mean logged users can access this queries) and 30% public query.
So i used public Authorization like this
type Product @model @auth(rules: [{allow: public, provider: apiKey, operations: [read]}]) {
id: ID!
name: String!
category_id: String
description: String
SKU: String
displayPrice: Float!
available: Boolean!
images: [ProductImage] @connection(name: "ProductImages")
categories: [ProductCat] @connection(name: "ProductCategories")
tags: [String!]!
reviews: [ProductReview] @connection(name: "ProductReview")
}
but its not working because i used on client like this.
function createApolloClient(initialState) {
const client = new AWSAppSyncClient(
{
url: config.aws_appsync_graphqlEndpoint,
region: config.aws_appsync_region,
auth: {
type: config.aws_appsync_authenticationType,
jwtToken: async () => (await Auth.currentSession()).getIdToken().getJwtToken()
}
},
);
return client;
}
so i added multiple apollo client like this.
function createApolloClient(initialState) {
const client = new AWSAppSyncClient(
{
url: config.aws_appsync_graphqlEndpoint,
region: config.aws_appsync_region,
auth: {
type: config.aws_appsync_authenticationType,
jwtToken: async () => (await Auth.currentSession()).getIdToken().getJwtToken()
}
},
);
const clientPublic = new AWSAppSyncClient(
{
url: config.aws_appsync_graphqlEndpoint,
region: config.aws_appsync_region,
auth: {type: AUTH_TYPE.API_KEY, apiKey: config.aws_appsync_apiKey},
}
);
if (userCheck() === true) {
return client;
}
return clientPublic;
}
after this everything works fine.
My question:
Hi @anarerdene, they work if you use them separately, but if you use them at the same time, you need multiple Apollo clients. A simpler way would be using Amplify Datastore instead of Apollo.