rsnext/examples/with-typescript-graphql
Jan Beseda bb81f2e6a6
fix(example): with-typescript-graphql graphql-let package migrate (#29996)
## Bug

- Partially fixes #25854 
- Badly specified package dependency version (`graphql-let`). The new major version required manual migration. As specified [here](https://github.com/piglovesyou/graphql-let/releases/tag/v0.18.0).
- In `lib/resolvers.ts`
```Module '"*.graphqls"' has no exported member 'MutationResolvers'. Did you mean to use 'import MutationResolvers from "*.graphqls"' instead?ts(2614)```


## Fixes

- Migrate as described in migration guide for `graphql-let` above.
- Update some npm packages along the way.
2022-02-06 17:48:51 +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 (example/with-typescript-grapql): fix deps (#26010) 2021-06-13 16:40:28 +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.

Preview

Preview the example live on StackBlitz:

Open in StackBlitz

Deploy your own

Deploy the example using Vercel:

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).