-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Doc] [NextJS] Walkthrough: Introspecting the GraphQL schema (#591)
* [Doc] [NextJS] Walkthrough: Introspecting the GraphQL schema * Add info about Fragment data * Change content order * Review language, rephrase for clarity * Tech review updates, fixed bullet Co-authored-by: Anca Emcken <[email protected]> Co-authored-by: Adam Brauer <[email protected]> Co-authored-by: Anastasiya Flynn <[email protected]>
- Loading branch information
1 parent
849948f
commit 3ad15b4
Showing
2 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
name: introspection | ||
routeTemplate: ./data/component-templates/article.yml | ||
title: Introspecting the GraphQL schema | ||
--- | ||
# Walkthrough: Introspecting the GraphQL schema | ||
|
||
One of the strengths of GraphQL is enforcing data types at runtime. Further, TypeScript and GraphQL code generation make it safer by typing data statically, so you can write type-protected code with rich IDE assists. The Next.js sample app uses [graphql-let](https://github.com/piglovesyou/graphql-let) for this purpose. | ||
|
||
> Read more about [how graphql-let works](https://github.com/piglovesyou/graphql-let#how-it-works). | ||
The file `.graphql-let.yml` in the sample app root contains configuration for `graphql-let`. | ||
|
||
> Read more about [graphql-let configuration](https://github.com/piglovesyou/graphql-let#configuration-is-compatible-with-codegenyml-except). | ||
When working with GraphQL in the sample Next.js application, you should be aware of two concepts: | ||
* **Introspection data**, which describes the queries supported by the GraphQL schema. Read more [here](https://graphql.org/learn/introspection). `graphq-let` uses this introspection data to understand which types it should use during code generation. | ||
* **Fragment data**, which is basic information about the shape of the GraphQL schema. Apollo Client supports caching GraphQL responses, which can greatly reduce network traffic needs. To work correctly with interfaces in GraphQL, the Apollo Client needs to know the information in this file. Read more [here](https://www.apollographql.com/docs/react/advanced/fragments.html#fragment-matcher). | ||
|
||
After you build the application for the first time, you will find: | ||
* `src/temp/GraphQLIntrospectionResult.json`, containing introspection data. | ||
* `src/temp/GraphQLFragmentTypes.json`, containing fragment data. | ||
|
||
When you alter Sitecore templates related to the site, you should update the introspection data. | ||
In the root of your Next.js application, run: | ||
|
||
``` | ||
jss graphql:update | ||
``` | ||
This script will fetch fresh introspection data and fragment data from your defined GraphQL endpoint and update the two files. | ||
|
||
The script `jss graphql:update` calls two other scripts: | ||
* `scripts/fetch-graphql-introspection-data.ts` is responsible for fetching introspection data. | ||
* `scripts/update-graphql-fragment-data.ts` is responsible for fetching fragment data. | ||
|
||
Both scripts use the `graphQLEndpoint` defined in `src/temp/config.js`, a file generated when you start your sample app for the first time. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters