Skip to content

Commit

Permalink
Adding GraphQL and Relay Modern named queries ex
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveyEdwards committed Aug 5, 2017
1 parent e6427cf commit a450563
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,41 @@ before passing it to the `resolveRoute` function:
see [path-to-regexp](https://github.com/pillarjs/path-to-regexp) documentation for details.


## Use with GraphQL and Relay Modern

To accomplish named queries with GraphQL and Relay you must pass in a object after your GraphQL query with the variables you need access to. In this example adding context was also needed

```jsx
import React from 'react';
import { graphql } from 'relay-runtime';
import MyiWorlds from './MyiWorlds';

export default {
path: '/myiworlds/:path',

async action({ api }, context) {
const data = await api.fetchQuery(graphql`
query myiWorldsQuery($path: String) {
n0deByPath (path: $path) {
id
type
n0deEdge {
...MyiWorlds_n0deEdge
}
}
}
`, {
path: context.path,
});
return {
title: 'MyiWorlds',
component: <MyiWorlds n0deEdge={data.n0deByPath.n0deEdge} />,
};
},
};
```


## Async Routes

The router works great with asynchronous functions out of the box!
Expand Down

0 comments on commit a450563

Please sign in to comment.