Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type 'CredentialsGetter | undefined' is not assignable to type 'CredentialsGetter' with createAppSyncLink #742

Open
OperationalFallacy opened this issue Apr 18, 2023 · 0 comments
Labels
bug Used as a label for bugs found in AppSync SDK p3

Comments

@OperationalFallacy
Copy link

Do you want to request a feature or report a bug?

I am unable to use the complexObjectsCredentials configuration option in the AWSAppSyncClient without encountering a TypeScript error.

What is the current behavior?

When attempting to use the complexObjectsCredentials configuration option in the AWSAppSyncClient, the following TypeScript error is generated:

Argument of type '{ resultsFetcherLink: ApolloLink; url: string; region: string; auth: AuthOptions; conflictResolver?: ConflictResolver | undefined; complexObjectsCredentials?: CredentialsGetter | undefined; cacheOptions?: ApolloReducerConfig | undefined; disableOffline?: boolean | undefined; offlineConfig?: OfflineConfig | undefined...' is not assignable to parameter of type '{ url: string; region: string; auth: AuthOptions; complexObjectsCredentials: CredentialsGetter; resultsFetcherLink?: ApolloLink | undefined; conflictResolver?: ConflictResolver | undefined; }'.
  Types of property 'complexObjectsCredentials' are incompatible.
    Type 'CredentialsGetter | undefined' is not assignable to type 'CredentialsGetter'.
      Type 'undefined' is not assignable to type 'CredentialsGetter'.ts(2345)

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.

The issue occurs when attempting to use the AWSAppSyncClient with the complexObjectsCredentials configuration option in a TypeScript project intended for use in an AWS Lambda function. The following code snippet demonstrates the setup:

The IAM temporary credentials generated by external process.

const credsReady = creds as NoUndefinedField<AwsCredentialIdentity>;
// Initialize the STS client
const sts = new STSClient({
  credentials: {
    accessKeyId: credsReady.accessKeyId,
    secretAccessKey: credsReady.secretAccessKey,
    sessionToken: credsReady.sessionToken,
  },
  region,
});

// Configure the AppSync client
const config: AWSAppSyncClientOptions = {
  url: apiUrl,
  region: region,
  auth: {
    type: AUTH_TYPE.AWS_IAM,
    credentials: async () => sts.config.credentials,
  },
  complexObjectsCredentials: () => Auth.currentCredentials(),
  disableOffline: true,
};

const client1 = new AWSAppSyncClient(config, {
  link: createAppSyncLink({
    ...config,
    resultsFetcherLink: ApolloLink.from([
      setContext((request, previousContext) => ({
        headers: {
          ...previousContext.headers,
          token: "1234"
        }
      })),
      createHttpLink({
        uri: config.url
      })
    ])
  })
});

What is the expected behavior?

The complexObjectsCredentials configuration option should be properly assigned

Which versions and which environment (browser, react-native, nodejs) / OS are affected by this issue? Did this work in previous versions?

Environment: Node.js (a TypeScript project intended to run on a host, no browser interaction)

@iartemiev iartemiev added p3 bug Used as a label for bugs found in AppSync SDK labels May 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Used as a label for bugs found in AppSync SDK p3
Projects
None yet
Development

No branches or pull requests

2 participants