LoginSignup
3
0

More than 5 years have passed since last update.

JavaScript版のAWSAppSyncClientにfragmentMatcherを設定する

Last updated at Posted at 2018-07-21

TL;DR

union型を扱った時にJavaScript版のAWSAppSyncClientにfragmentMatcherを設定する方法がなかなかわからなかったので共有しておきます。
(apollo-clientの情報は結構見つかりました)

version

aws-appsync@1.1.4

code

JavaScript版と書いていますが以下はTypeScriptです。すいません。

import { IntrospectionFragmentMatcher } from 'apollo-cache-inmemory';
import { AWSAppSyncClient, AUTH_TYPE } from 'aws-appsync';

const fragmentMatcher: IntrospectionFragmentMatcher = new IntrospectionFragmentMatcher({
  introspectionQueryResultData: {
    __schema: {
      types: [] // no types provided
    }
  }
});
const client: AWSAppSyncClient = new AWSAppSyncClient({
  url: ENV.awsAppSync.graphqlEndpoint,
  region: ENV.awsAppSync.region,
  auth: {
    type: AUTH_TYPE.OPENID_CONNECT,
    jwtToken: async () => getAccessToken()
  },
  cacheOptions: {
    fragmentMatcher: fragmentMatcher
  }
});

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0