rsnext/examples/with-typescript-graphql
Steven 9f9214abe5
Updated create-next-app docs to include pnpm usage (#35755)
This PR updates the docs and examples for `create-next-app` to include pnpm usage.

The following script was used to update every example README:

```js
const fs = require('fs')
const examples = fs.readdirSync('./examples')

for (let example of examples) {
    const filename = `./examples/${example}/README.md`
    const markdown = fs.readFileSync(filename, 'utf8')
    const regex = new RegExp(`^yarn create next-app --example (.*)$`, 'gm')
    const output = markdown.replace(regex, (yarn, group) => {
        const pnpm = `pnpm create next-app -- --example ${group}`
        return `${yarn}\n# or\n${pnpm}`
    })
    fs.writeFileSync(filename, output)
}
```
2022-03-30 21:03:21 +00:00
..
lib [with-typescript-graphql] fixes breaking changes in graphql-let v0.18.0 (#32681) 2022-02-06 11:20:55 -06:00
pages Fix typescript types. (#23771) 2021-04-15 18:55:30 +00:00
test Add mutation example to with-typescript-graphql (#16742) 2020-11-10 21:10:54 +00:00
.babelrc fix(example): with-typescript-graphql graphql-let package migrate (#29996) 2022-02-06 17:48:51 +00:00
.gitignore fix(example): with-typescript-graphql graphql-let package migrate (#29996) 2022-02-06 17:48:51 +00:00
.graphql-let.yml [with-typescript-graphql] fixes breaking changes in graphql-let v0.18.0 (#32681) 2022-02-06 11:20:55 -06:00
graphql.d.ts next-env.d.ts note in templates (#27983) 2021-08-12 20:36:53 +00:00
jest.config.js fix: Order moduleFileExtensions left-to-right (#18328) 2020-10-27 20:20:03 +00:00
next-env.d.ts Include submodules in exported type definition (#28316) 2021-11-26 14:46:56 +01:00
next.config.js Update with-typescript-graphql (#16101) 2020-08-29 22:15:50 -04:00
package.json fix(example): with-typescript-graphql graphql-let package migrate (#29996) 2022-02-06 17:48:51 +00:00
README.md Updated create-next-app docs to include pnpm usage (#35755) 2022-03-30 21:03:21 +00:00
tsconfig.json [with-typescript-graphql] fixes breaking changes in graphql-let v0.18.0 (#32681) 2022-02-06 11:20:55 -06:00

TypeScript and GraphQL Example

One of the strengths of GraphQL is enforcing data types on runtime. Further, TypeScript and GraphQL Code Generator (graphql-codegen) make it safer by typing data statically, so you can write truly type-protected code with rich IDE assists.

This template extends Apollo Server and Client Example by rewriting in TypeScript and integrating graphql-let, which runs TypeScript React Apollo in graphql-codegen under the hood. It enhances the typed GraphQL use as below:

import { useNewsQuery } from './news.graphql'

const News = () => {
	// Typed already
	const { data: { news } } = useNewsQuery()

	return <div>{news.map(...)}</div>
}

By default **/*.graphqls is recognized as GraphQL schema and **/*.graphql as GraphQL documents. If you prefer the other extensions, make sure the settings of the webpack loader in next.config.js and .graphql-let.yml are consistent.

Deploy your own

Deploy the example using Vercel or preview live with StackBlitz

Deploy with Vercel

How to use

Execute create-next-app with npm or Yarn to bootstrap the example:

npx create-next-app --example with-typescript-graphql with-typescript-graphql-app
# or
yarn create next-app --example with-typescript-graphql with-typescript-graphql-app
# or
pnpm create next-app -- --example with-typescript-graphql with-typescript-graphql-app

Deploy it to the cloud with Vercel (Documentation).