Skip to content

Commit

Permalink
Update README with rawRequest method example
Browse files Browse the repository at this point in the history
  • Loading branch information
lukehedger committed Feb 23, 2018
1 parent 9e689c9 commit d17b819
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const query = `{
}
}
}`

request('https://api.graph.cool/simple/v1/movies', query).then(data => console.log(data))
```

Expand All @@ -44,7 +44,7 @@ request(endpoint, query, variables).then(data => console.log(data))

// ... or create a GraphQL client instance to send requests
const client = new GraphQLClient(endpoint, { headers: {} })
client.request(query, variables).then(data => console.log(data))
client.request(query, variables).then(data => console.log(data))
```

## Examples
Expand All @@ -69,7 +69,7 @@ const query = `{
}
}`

client.request(query).then(data => console.log(data))
client.request(query).then(data => console.log(data))
```

### Passing more options to fetch
Expand All @@ -91,7 +91,7 @@ const query = `{
}
}`

client.request(query).then(data => console.log(data))
client.request(query).then(data => console.log(data))
```

### Using variables
Expand Down Expand Up @@ -145,7 +145,7 @@ const query = `{
}
}
}`

request('my-endpoint', query).then(data => console.log(data))
```

Expand Down Expand Up @@ -175,6 +175,26 @@ const query = `{
client.request(query).then(data => console.log(data))
```

### Receiving a raw response

The `request` method will return the `data` or `errors` key from the response.
If you need to access the `extensions` key you can use the `rawRequest` method:

```js
import { rawRequest } from 'graphql-request'

const query = `{
Movie(title: "Inception") {
releaseDate
actors {
name
}
}
}`

rawRequest('my-endpoint', query).then(({data, extensions}) => console.log(data, extensions))
```

### More examples coming soon...

* Fragments
Expand Down

0 comments on commit d17b819

Please sign in to comment.