Skip to content

Commit

Permalink
docs: Add example for Mutations to README (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
brianjychan authored Aug 28, 2020
1 parent 8bdb803 commit 762735b
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,42 @@ async function main() {
main().catch((error) => console.error(error))
```

### Mutations

```js
import { GraphQLClient, gql } from 'graphql-request'

async function main() {
const endpoint = 'https://api.graph.cool/simple/v1/cixos23120m0n0173veiiwrjr'

const graphQLClient = new GraphQLClient(endpoint, {
headers: {
authorization: 'Bearer MY_TOKEN',
},
})

const mutation = gql`
mutation AddMovie($title: String!, $releaseDate: Int!) {
insert_movies_one(object: { title: $title, releaseDate: $releaseDate }) {
title
releaseDate
}
}
`

const variables = {
title: 'Inception',
releaseDate: 2010
}
const data = await graphQLClient.request(mutation, variables)

console.log(JSON.stringify(data, undefined, 2))
}

main().catch((error) => console.error(error))
```


[TypeScript Source](examples/using-variables.ts)

### Error handling
Expand Down

0 comments on commit 762735b

Please sign in to comment.