Skip to content

Instantly share code, notes, and snippets.

@colinfwren
Created August 4, 2024 20:15
Show Gist options
  • Save colinfwren/eedcf345f1f5d76e5d30b0035e1efd7f to your computer and use it in GitHub Desktop.
Save colinfwren/eedcf345f1f5d76e5d30b0035e1efd7f to your computer and use it in GitHub Desktop.
Calling GraphQL via HTTP
const graphqlString = `
mutation Something($somethingData: SomethingInput!) {
something(somethingData: $somethingData) {
name
}
}
`
test('something that requires user auth', async () => {
const { jwt } = await getNewUser()
const graphqlCall = await request(url)
.post('/')
.set('Authorization', `Bearer ${jwt}`)
.send({
query: graphqlString,
variables: {
somethingData: {
name: 'whatever'
}
}
})
expect(graphCall.body.errors).toBeUndefined()
expect(graphCall.body.data.something).toMatchObject({
name: 'whatever'
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment