-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split the local state section up into separate pages, to make it easier to read through related concepts. This also helps ensure the right hand menu can help show relevant subsections, that were previously buried under level 3 and 4 titles.
- Loading branch information
Showing
8 changed files
with
256 additions
and
315 deletions.
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
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
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,37 @@ | ||
--- | ||
title: Client-side schema | ||
description: Configure a client-side schema with Apollo Client | ||
--- | ||
|
||
You can optionally set a client-side schema to be used with Apollo Client, through either the `ApolloClient` constructor `typeDefs` parameter, or the local state API `setTypeDefs` method. Your schema should be written in [Schema Definition Language](https://www.apollographql.com/docs/graphql-tools/generate-schema#schema-language). This schema is not used for validation like it is on the server because the `graphql-js` modules for schema validation would dramatically increase your bundle size. Instead, your client-side schema is used for introspection in [Apollo Client Devtools](https://github.com/apollographql/apollo-client-devtools), where you can explore your schema in GraphiQL. | ||
|
||
The following demonstrates how to configure a client-side schema through the `ApolloClient` constructor: | ||
|
||
```js | ||
import { ApolloClient, InMemoryCache, gql } from '@apollo/client'; | ||
|
||
const typeDefs = gql` | ||
extend type Query { | ||
isLoggedIn: Boolean! | ||
cartItems: [Launch]! | ||
} | ||
extend type Launch { | ||
isInCart: Boolean! | ||
} | ||
extend type Mutation { | ||
addOrRemoveFromCart(id: ID!): [Launch] | ||
} | ||
`; | ||
|
||
const client = new ApolloClient({ | ||
cache: new InMemoryCache(), | ||
uri: 'http://localhost:4000/graphql', | ||
typeDefs, | ||
}); | ||
``` | ||
|
||
If you open up Apollo Client Devtools and click on the `GraphiQL` tab, you'll be able to explore your client schema in the "Docs" section. This example doesn't include a remote schema, but if it did, you would be able to see your local queries and mutations alongside your remote ones. | ||
|
||
![GraphiQL Console](../assets/client-schema.png) |
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
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
Oops, something went wrong.