Atlas is available as an npm package.
Check out the latest Storybook to learn how to use the library.
- Download GraphQL for VS Code
- Download Watchman
- Add a
.graphqlconfig
file to the root of your project with the following contents:
{
schema: {
files: 'schema.graphql',
},
query: {
files: [
{
match: ['src/**/*.js', 'src/**/*.tsx'],
parser: ['EmbeddedQueryParser', { startTag: 'gql`', endTag: '`' }],
},
],
},
}
- Visit https://graphql-code-generator.com/
- Paste your schema.graphql file into the generator with the following options:
generates:
server-types.ts:
config:
avoidOptionals: true
maybeValue: T
plugins:
- typescript
-
Add the output to a types file in your project.
-
Make queries
const query = gql`
query {
metacardsByTag(tag: "query-template") {
status {
hits
}
attributes {
title
id
created
modified
description
metacard_owner
}
}
}
`
const { data, error, loading } = useQuery<InsertTypescriptTypeHere>(query)
if (loading) return <div>Loading</div>
if (error) return <div>Error</div>
if (!data) {
return <div>Error</div>
}
const response = data.metacardsByTag