13

I'm trying to call a service through Graphql with Postman. From my app (React) I can use all the services with no problem (so, they are running ok), but I want to test them alone with Postman.

I'm using AppSync, this is my configuration:

const AppSyncConfig = {
  url: environments.configAws.graphql.aws_appsync_graphqlEndpoint,
  region: environments.configAws.graphql.aws_appsync_region,
  auth: {
    type: AUTH_TYPE.API_KEY,
    apiKey: environments.configAws.graphql.aws_appsync_apiKey,
  }
};

The environments vars are this:

graphql: {
    aws_project_region: "us-east-1",

    aws_appsync_graphqlEndpoint: "https://XXXXXXXXXXXXX.appsync-api.us-east-1.amazonaws.com/graphql",
    aws_appsync_region: "us-east-1",
    aws_appsync_authenticationType: "API_KEY",
    aws_appsync_apiKey: "da2-XXXXXXXXXXXX"
}

And the app use this to make a query:

const client = new AWSAppSyncClient(AppSyncConfig, {
  link: createAppSyncLink({ ...AppSyncConfig,
    resultsFetcherLink: ApolloLink.from([
      setContext((request, previousContext) => ({
        headers: { ...previousContext.headers,
          Authorization: localStorage.getItem('token') ? localStorage.getItem('token') : ''
        }
      })),
      createHttpLink({
        uri: AppSyncConfig.url
      })
    ])
  })
});

const data_configs = client.readQuery({ query: query_configs });

In Postman I have this config, but I'm getting an error:

enter image description here

I took this code today, I haven't work before with Graphql (so neither with AppSync, ApolloLink, etc), but I ask in case it has a simple solution, or at least a hint for what should I check. Thanks.

Alessio
  • 3,404
  • 19
  • 35
  • 48
pmiranda
  • 7,602
  • 14
  • 72
  • 155

5 Answers5

18

I believe the header name for the API KEY is not API_KEY but x-api-key.

Ionut Trestian
  • 5,473
  • 2
  • 20
  • 29
12

I was able to invoke my AWS Amplify GraphQL endpoint with Postman using the following steps:

  1. Create a new Postman request
  2. Set the type of request to 'POST'
  3. Enter the API URL in the request URL
  4. Add a header of 'x-api-key': {{API KEY}} in the Headers tab
  5. Add a body of consisting of a well formed GraphQL query
  6. Click Send
Eric Spiegelberg
  • 602
  • 1
  • 8
  • 14
1

Put "x-api-id" in the request header works for me.

JES
  • 21
  • 1
1

Here is the images which I have implemented in Postman. First image has header and other details, and in Second image check Raw Body Section. enter image description here

enter image description here

DharmanBot
  • 1,066
  • 2
  • 6
  • 10
Mohsin Khan
  • 131
  • 1
  • 1
  • 10
1

It's the screenshot for 'x-api-key' from the Authentication tab in Postman. Its type is API Key and it can be also used like this.

Authentication header

afaik
  • 56
  • 4