Unverified Commit bb0013f5 authored by Max Proske's avatar Max Proske Committed by GitHub

chore(examples): Convert `api-routes-graphql` example to TypeScript (#38357)

Convert `api-routes-graphql` example to TypeScript to match Contribution docs.

## Documentation / Examples

- [X] Make sure the linting passes by running `pnpm lint`
- [X] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
parent b8efd80c
...@@ -32,3 +32,6 @@ yarn-error.log* ...@@ -32,3 +32,6 @@ yarn-error.log*
# vercel # vercel
.vercel .vercel
# typescript
*.tsbuildinfo
/// <reference types="next" />
/// <reference types="next/image-types/global" />
// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
...@@ -6,11 +6,17 @@ ...@@ -6,11 +6,17 @@
"start": "next start" "start": "next start"
}, },
"dependencies": { "dependencies": {
"@graphql-yoga/node": "^2.2.1", "@graphql-yoga/node": "^2.11.2",
"graphql": "^16.3.0", "graphql": "^16.5.0",
"next": "latest", "next": "latest",
"react": "^17.0.2", "react": "^18.2.0",
"react-dom": "^17.0.2", "react-dom": "^18.2.0",
"swr": "^0.5.6" "swr": "^1.3.0"
},
"devDependencies": {
"@types/node": "^18.0.2",
"@types/react": "^18.0.15",
"@types/react-dom": "^18.0.6",
"typescript": "^4.7.4"
} }
} }
...@@ -11,7 +11,7 @@ const typeDefs = /* GraphQL */ ` ...@@ -11,7 +11,7 @@ const typeDefs = /* GraphQL */ `
const resolvers = { const resolvers = {
Query: { Query: {
users(parent, args, context) { users() {
return [{ name: 'Nextjs' }] return [{ name: 'Nextjs' }]
}, },
}, },
......
import useSWR from 'swr' import useSWR from 'swr'
const fetcher = (query) => const fetcher = (query: string) =>
fetch('/api/graphql', { fetch('/api/graphql', {
method: 'POST', method: 'POST',
headers: { headers: {
...@@ -21,7 +21,7 @@ export default function Index() { ...@@ -21,7 +21,7 @@ export default function Index() {
return ( return (
<div> <div>
{users.map((user, i) => ( {users.map((user: any, i: number) => (
<div key={i}>{user.name}</div> <div key={i}>{user.name}</div>
))} ))}
</div> </div>
......
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment