Created
August 4, 2024 20:15
-
-
Save colinfwren/eedcf345f1f5d76e5d30b0035e1efd7f to your computer and use it in GitHub Desktop.
Calling GraphQL via HTTP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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