Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Postman to test a service with GraphQL in AWS (AppSync, Apollo)

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.

like image 666
pmiranda Avatar asked Dec 11 '19 14:12

pmiranda


2 Answers

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

like image 106
Ionut Trestian Avatar answered Sep 30 '22 00:09

Ionut Trestian


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
like image 25
Eric Spiegelberg Avatar answered Sep 30 '22 00:09

Eric Spiegelberg