rsnext/examples/with-typescript-graphql
Hassan El Mghari 33aa51ab26
Change README structure in examples (#35349)
Changed the README structure in all examples to take out the Stackblitz button and include it as a link instead using a [bash script](https://gist.github.com/Nutlope/a8f3556a5a401e32a8c6278b782ebf8a/revisions).

I also added the Vercel deploy button to 15 READMEs that didn't have it.
2022-03-16 21:39:26 +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 Change README structure in examples (#35349) 2022-03-16 21:39:26 +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

Deploy it to the cloud with Vercel (Documentation).