Accessing Headers/Secrets in the Apollo Launchpad

Hi, I am trying to figure how headers work in the context of launchpad. In the hello world example is mentions grabbing the context from the request https://launchpad.graphql.com/new

Though Spotify example does not use it: https://launchpad.graphql.com/pjwnq05l0

For more context this is pad I created trying use the Netlify API to wrap GraphQL around an existing REST API. In my header, I have created

const resolvers = {
  Query: {
    user: (root, args, context) => {
      return fetch('https://api.netlify.com/api/v1/user', {
        method: "POST",
        headers: `Authorization: bearer ${context.headers.access_token}`
      })
      	.then(res => res.json()).catch(err => console.log(err));
    },
  },
};

I also tried process.env.access_token instead of context.headers.access_token.

Is there something I am missing?

I figured this out. I read the brief documentation in the repo and saw there you can use secrets as well.

const resolvers = {
  Query: {
    user: (root, args, context) => {
      return fetch(`https://api.netlify.com/api/v1/user?access_token=${context.secrets.ACCESS_TOKEN}`)
      	.then(res => res.json()).catch(err => console.log(err));
    },
  },
};

I was also trying to access the Netlify API incorrectly as well. The token needed to be a query param and not in the headers.

1 Like