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

Error while executing GraphQL statement Error: Must provide Source. Received: undefined #147

Open
pkubat opened this issue Jan 18, 2022 · 2 comments

Comments

@pkubat
Copy link

pkubat commented Jan 18, 2022

Describe the bug
This is a direct lambda query/datasource. It works fine deployed to AWS but dies not to work locally. Not sure how to debug/trace as SLS_DEBUG does not generate traces or output from the queries.

To Reproduce
npx sls offline start and query the service

sample query

curl -X "POST" "http://localhost:20002/graphql" \
     -H 'x-api-key: 0123456789' \
     -H 'Content-Type: application/graphql' \
     -d $'{
	"query": "query MyQuery{listBooks{title}}",
	"variables": {}
}'

Expected behavior

Screenshots

Additional context

  plugins: [
    'serverless-appsync-plugin',
    'serverless-appsync-simulator',
    'serverless-offline',
    'serverless-esbuild',
  ],
    appSync: {
      name: 'service-members-ledgers',
      authenticationType: 'API_KEY',
      apiKeys: [ {
        name: 'key 1',
        description: 'asdasd',
        expiresAfter: '30d',
      }],
      mappingTemplates: [{
        type: 'Query',
        request: false,
        response: false,
        dataSource: '_ds_appSyncTest',
        field: 'listBooks',
      }],
      dataSources: [{
        type: 'AWS_LAMBDA',
        name: '_ds_appSyncTest',
        config: {
          functionName: 'appSyncTest'
        }
      }],
    },

SLS+DEBUG=*

AppSync Simulator: AppSync Config service-members-ledgers
AppSync Simulator: {
  appSync: {
    name: 'service-members-ledgers',
    apiKey: '0123456789',
    defaultAuthenticationType: { authenticationType: 'API_KEY' },
    additionalAuthenticationProviders: []
  },
  schema: {
    path: 'schema.graphql',
    content: 'schema {\n' +
      '  query: Query\n' +
      '}\n' +
      '\n' +
      'type Book {\n' +
      '  title: String\n' +
      '}\n' +
      '\n' +
      'type Query {\n' +
      '  listBooks: [Book]\n' +
      '}'
  },
  resolvers: [
    {
      kind: 'UNIT',
      fieldName: 'listBooks',
      typeName: 'Query',
      dataSourceName: '_ds_appSyncTest',
      functions: undefined,
      requestMappingTemplate: '## Direct lambda request\n' +
        '{\n' +
        '    "version": "2018-05-29",\n' +
        '    "operation": "Invoke",\n' +
        '    "payload": $utils.toJson($context)\n' +
        '}\n',
      responseMappingTemplate: '## Direct lambda response\n' +
        '#if($ctx.error)\n' +
        '    $util.error($ctx.error.message, $ctx.error.type, $ctx.result)\n' +
        '#end\n' +
        '$util.toJson($ctx.result)\n'
    }
  ],
  dataSources: [
    {
      name: '_ds_appSyncTest',
      type: 'AWS_LAMBDA',
      invoke: [AsyncFunction: invoke]
    }
  ],
  functions: []
}
@pkubat
Copy link
Author

pkubat commented Jan 19, 2022

This is caused by the use of an HTTP header Content-Type:application/graphql which is used in AWS's examples at https://docs.aws.amazon.com/appsync/latest/devguide/security-authz.html#api-key-authorization. It seems that the request ends up as any empty object {}

The workaround for this is to drop the header Content-Type:application/graphql or use application/json

@bboure
Copy link
Member

bboure commented Feb 17, 2022

Thank you @pkubat
I think this issue is probably on https://github.com/aws-amplify/amplify-cli/
it might be worth opening an issue there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants