Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
throw error when fragment is not loaded
update docs to latest apollo local state and gatsby
  • Loading branch information
dotansimha committed Mar 31, 2019
1 parent d655355 commit 72ddabc
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
@@ -1,9 +1,9 @@
---
id: apollo-link-state
title: apollo-link-state
id: apollo-local-state
title: Apollo Local State
---

If you are using [apollo-client](https://www.apollographql.com/docs/react/) and [apollo-link-state](https://www.apollographql.com/docs/link/links/state.html) to manage your app state with GraphQL, you're probably using a client-side only GraphQL schema and client-side directives such as `@client`.
If you are using [apollo-client](https://www.apollographql.com/docs/react/essentials/local-state) >2.5 (or older, with [apollo-link-state](https://www.apollographql.com/docs/link/links/state.html)) to manage your app state with GraphQL, you're probably using a client-side only GraphQL schema and client-side directives such as `@client`.

Thses types and directives are not part of your remote GraphQL schema.

Expand Down
24 changes: 24 additions & 0 deletions docs/integrations/gatsby.md
@@ -0,0 +1,24 @@
---
id: gatsby
title: GatsbyJS
---

If you are building apps using [GatsbyJS](https://www.gatsbyjs.org/), you can intergrate GraphQL Code Generator and use it to generate types.

The codegen knows automatically to look for the import of the `graphql` tag for `gatsby` package.

Using the following config file, it should cover everything specific to Gastby:

```yml
schema: http://localhost:8000/___graphql
documents:
- ./src/**/*.{ts,tsx}
- ./node_modules/gatsby-*/**/*.js
generates:
./src/graphqlTypes.ts:
plugins:
- typescript
- typescript-operations
```

Now, the codegen should be able to load your GraphQL operations from your source code, and also load all the internal fragments from `node_modules`.
Expand Up @@ -112,6 +112,10 @@ export class SelectionSetToObject {
_collectFragmentSpread(node: FragmentSpreadNode) {
const loadedFragment = this._loadedFragments.find(f => f.name === node.name.value);

if (!loadedFragment) {
throw new Error(`Unable to find fragment matching then name "${node.name.value}"! Please make sure it's loaded.`);
}

if (!this._fragments[loadedFragment.onType]) {
this._fragments[loadedFragment.onType] = [];
}
Expand Down
2 changes: 1 addition & 1 deletion website/sidebars.json
Expand Up @@ -29,7 +29,7 @@
"plugins/schema-ast",
"plugins/reason-client"
],
"Integrations": ["integrations/apollo-link-state", "integrations/create-react-app"],
"Integrations": ["integrations/apollo-local-state", "integrations/create-react-app", "integrations/gatsby"],
"Custom Code-Generator Plugins": ["custom-codegen/index", "custom-codegen/write-your-plugin", "custom-codegen/validate-configuration", "custom-codegen/extend-schema", "custom-codegen/using-visitor"],
"Migration": ["migration/from-0-18", "migration/from-0-13"]
}
Expand Down

0 comments on commit 72ddabc

Please sign in to comment.