1

I was trying to test APQ with a server written in haskell. The following is the sample Apollo client code, I wrote to test it:

const { createPersistedQueryLink } = require("apollo-link-persisted-queries")
const { createHttpLink } = require("apollo-link-http")
const { InMemoryCache } = require("apollo-cache-inmemory")
const { ApolloClient } = require("apollo-client")
const { gql } = require('apollo-server');
const { ApolloLink } = require("apollo-link")
const fetch  = require("node-fetch")

const link = ApolloLink.from([
  createPersistedQueryLink(),
  createHttpLink({ 
    uri: "http://localhost:8080/v1/graphql",
    fetch: fetch,
    headers: {
    "admin-secret":"password"
    } 
  })
]);



const client = new ApolloClient({
 cache: new InMemoryCache(),
 link: link
})


async function main() {
  const response = await client
  .query({
    query: gql`
      query {
        child {
          name
        }
      }`
  })
  console.log(response.data)
}

main().catch(err => console.log("Err:", err))

But whenever I run this file, I get the following error:

graphQLErrors: [
    {
      extensions: [Object],
      message: "the key 'query' was not present"
    }
  ],

When I check the Request body sent in POST Body, I get the following thing:

{"operationName":null,"variables":{},"extensions":{"persistedQuery":{"version":1,"sha256Hash":"0832c514aef4b1a6d84702e8b2fab452cbb0af61f0a1c4a4c30405e671d40527"}}}

It tells that the query is not sent in the Post Body. Which might be the reason I'm getting the above error.

Hence, I am confused at this point :see_no_evil:

I read through a tons of blogs, but It's not clear as to what HTTP method is used when { useGETForHashedQueries: true } option is not given. From my experiment above, it looks as if - POST method is used.

But if POST method is used, why isn't the query sent in the POST body.

BUT

When I use the { useGETForHashedQueries: true } option, it works correctly. What might I be doing wrong here?

It would be really great, if someone would clear this out for me.

Naveen
  • 85
  • 8

0 Answers0