Need mutation example on how to use graphql-request sdk #8422
-
The example provide here only has a query. https://www.the-guild.dev/graphql/codegen/plugins/typescript/typescript-graphql-request Can someone provide me with an example showing how to use it for mutation with variables? |
Beta Was this translation helpful? Give feedback.
Answered by
charlypoly
Oct 3, 2022
Replies: 1 comment
-
Hi @RedFour, A mutation has the same signature as a query, with variables as the first argument of the SDK method, as shown below: import { GraphQLClient } from 'graphql-request'
import { getSdk } from './sdk' // THIS FILE IS THE GENERATED FILE
async function main() {
const client = new GraphQLClient('https://countries.trevorblades.com')
const sdk = getSdk(client)
const { continent } = await sdk.createContinent({ name: "Europe" }) // This is fully typed, based on the query
console.log(`GraphQL data:`, continent)
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
charlypoly
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @RedFour,
A mutation has the same signature as a query, with variables as the first argument of the SDK method, as shown below: