Skip to content

Commit

Permalink
chore(examples): Convert api-routes-graphql example to TypeScript (#…
Browse files Browse the repository at this point in the history
…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)
  • Loading branch information
maxproske authored Jul 8, 2022
1 parent b8efd80 commit bb0013f
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 8 deletions.
3 changes: 3 additions & 0 deletions examples/api-routes-graphql/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ yarn-error.log*

# vercel
.vercel

# typescript
*.tsbuildinfo
5 changes: 5 additions & 0 deletions examples/api-routes-graphql/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <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.
16 changes: 11 additions & 5 deletions examples/api-routes-graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@
"start": "next start"
},
"dependencies": {
"@graphql-yoga/node": "^2.2.1",
"graphql": "^16.3.0",
"@graphql-yoga/node": "^2.11.2",
"graphql": "^16.5.0",
"next": "latest",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"swr": "^0.5.6"
"react": "^18.2.0",
"react-dom": "^18.2.0",
"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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const typeDefs = /* GraphQL */ `

const resolvers = {
Query: {
users(parent, args, context) {
users() {
return [{ name: 'Nextjs' }]
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import useSWR from 'swr'

const fetcher = (query) =>
const fetcher = (query: string) =>
fetch('/api/graphql', {
method: 'POST',
headers: {
Expand All @@ -21,7 +21,7 @@ export default function Index() {

return (
<div>
{users.map((user, i) => (
{users.map((user: any, i: number) => (
<div key={i}>{user.name}</div>
))}
</div>
Expand Down
20 changes: 20 additions & 0 deletions examples/api-routes-graphql/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"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"]
}

0 comments on commit bb0013f

Please sign in to comment.