Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@beeplin
Copy link
Contributor

@beeplin beeplin commented Jun 17, 2020

Currently ctx.client.headers does not work in nexus/testing due to the structural mismatch between Headers incross-fetch and Headers ingraphql-request.

This PR converts headers from cross-fetch format to a simple plain object, so that GraphQLClient from graphql-request can consume it.

Currently `ctx.client.headers` does not work in `nexus/testing` due to the structural mismatch between `Headers` in`cross-fetch` and `Headers` in`graphql-request`. 

This PR converts `headers` from `cross-fetch` format to a simple plain object, so that `GraphQLClient` from `graphql-request` can consume it.
@jasonkuhrt
Copy link
Member

Hey @beeplin can you expand on the problem? I am able to work with headers fine on the hello-world example.

@jasonkuhrt jasonkuhrt added the needs/clarification Unable to answer question/feature without more info label Jun 17, 2020
@beeplin
Copy link
Contributor Author

beeplin commented Jun 18, 2020

@jasonkuhrt Please check https://github.com/beeplin/examples/commit/7ebb49e4096c8c3d171e87431805c36e1b201df2 to see my test.

Currently I dont' see any tests covering ctx.client.headers in the nexus/examples repo, so I made my own simple test in hello-world. Given a testHeader resolver returning the test header:

    t.field("testHeader", {
      type: "String",
      resolve(root, args, ctx) {
        return ctx.req.headers.test
      }
    })

And set test header with ctx.client.headers:

it("test headers", async () => {
  ctx.client.headers.set({ test: "this is a header test" })
  expect(
    await ctx.client.send(`
      query {
        testHeader
      }
    `)
  ).toMatchInlineSnapshot(`
    Object {
      "testHeader": "this is a header test",
    }
  `)
})

With the currently nexus 0.24.2 the test fails, and we can see the test header is not sent to the graphql client. With the fix shown in this PR, the test works.

@jasonkuhrt jasonkuhrt removed the needs/clarification Unable to answer question/feature without more info label Jun 20, 2020
Copy link
Member

@jasonkuhrt jasonkuhrt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @beeplin!

@jasonkuhrt jasonkuhrt changed the title fix(graphql-client): make ctx.client.headers work fix(testing): ctx.client sends set headers Jun 20, 2020
@jasonkuhrt jasonkuhrt merged commit 56b4759 into prisma-labs:master Jun 20, 2020
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

Successfully merging this pull request may close these issues.

2 participants