Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(docs): add Readme section for GET requests #370

Merged
merged 1 commit into from
Jul 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Minimal GraphQL client supporting Node and browsers for scripts or simple apps
- [Passing more options to `fetch`](#passing-more-options-to-fetch)
- [Custom JSON serializer](#custom-json-serializer)
- [Using GraphQL Document variables](#using-graphql-document-variables)
- [Making a GET request](#making-a-get-request)
- [GraphQL Mutations](#graphql-mutations)
- [Error handling](#error-handling)
- [Using `require` instead of `import`](#using-require-instead-of-import)
Expand Down Expand Up @@ -328,6 +329,46 @@ async function main() {
main().catch((error) => console.error(error))
```

### Making a GET request

Queries can be sent as an HTTP GET request:

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

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

const graphQLClient = new GraphQLClient(endpoint, {
method: 'GET',
jsonSerializer: {
parse: JSON.parse,
stringify: JSON.stringify,
},
});

const query = gql`
query getMovie($title: String!) {
Movie(title: $title) {
releaseDate
actors {
name
}
}
}
`

const variables = {
title: 'Inception',
}

const data = await graphQLClient.request(query, variables)
console.log(JSON.stringify(data, undefined, 2))
}

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

### GraphQL Mutations

```js
Expand Down