Skip to content

Commit

Permalink
Merge branch 'canary' into app-search-params
Browse files Browse the repository at this point in the history
  • Loading branch information
Hannes Bornö committed Oct 24, 2022
2 parents 6fb5e9e + c5111f7 commit f9fe62d
Show file tree
Hide file tree
Showing 62 changed files with 887 additions and 341 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Expand Up @@ -34,3 +34,4 @@ packages/next-swc/crates/**
bench/nested-deps/pages/**
bench/nested-deps/components/**
packages/next-bundle-analyzer/index.d.ts
examples/with-typescript-graphql/lib/gql/
2 changes: 1 addition & 1 deletion docs/advanced-features/custom-error-page.md
Expand Up @@ -74,7 +74,7 @@ import Error from 'next/error'

export async function getServerSideProps() {
const res = await fetch('https://api.github.com/repos/vercel/next.js')
const errorCode = res.ok ? false : res.statusCode
const errorCode = res.ok ? false : res.status
const json = await res.json()

return {
Expand Down
18 changes: 9 additions & 9 deletions examples/with-tailwindcss/package.json
Expand Up @@ -7,16 +7,16 @@
},
"dependencies": {
"next": "latest",
"react": "18.1.0",
"react-dom": "18.1.0"
"react": "18.2.0",
"react-dom": "18.2.0"
},
"devDependencies": {
"@types/node": "17.0.35",
"@types/react": "18.0.9",
"@types/react-dom": "18.0.5",
"autoprefixer": "^10.4.7",
"postcss": "^8.4.14",
"tailwindcss": "^3.1.2",
"typescript": "4.7.2"
"@types/node": "18.11.3",
"@types/react": "18.0.21",
"@types/react-dom": "18.0.6",
"autoprefixer": "^10.4.12",
"postcss": "^8.4.18",
"tailwindcss": "^3.2.1",
"typescript": "4.8.4"
}
}
23 changes: 23 additions & 0 deletions examples/with-typescript-graphql/codegen.ts
@@ -0,0 +1,23 @@
import type { CodegenConfig } from '@graphql-codegen/cli'

const config: CodegenConfig = {
schema: [
{
'lib/schema.ts': {
noRequire: true,
},
},
],
documents: './pages/**/*.tsx',
generates: {
'./lib/gql/': {
preset: 'client',
plugins: [],
},
'./lib/resolvers-types.ts': {
plugins: ['typescript', 'typescript-resolvers'],
},
},
}

export default config
14 changes: 0 additions & 14 deletions examples/with-typescript-graphql/codegen.yml

This file was deleted.

This file was deleted.

11 changes: 0 additions & 11 deletions examples/with-typescript-graphql/lib/documents/viewer.graphql

This file was deleted.

44 changes: 44 additions & 0 deletions examples/with-typescript-graphql/lib/gql/fragment-masking.ts
@@ -0,0 +1,44 @@
import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'

export type FragmentType<TDocumentType extends DocumentNode<any, any>> =
TDocumentType extends DocumentNode<infer TType, any>
? TType extends { ' $fragmentName'?: infer TKey }
? TKey extends string
? { ' $fragmentRefs'?: { [key in TKey]: TType } }
: never
: never
: never

// return non-nullable if `fragmentType` is non-nullable
export function useFragment<TType>(
_documentNode: DocumentNode<TType, any>,
fragmentType: FragmentType<DocumentNode<TType, any>>
): TType
// return nullable if `fragmentType` is nullable
export function useFragment<TType>(
_documentNode: DocumentNode<TType, any>,
fragmentType: FragmentType<DocumentNode<TType, any>> | null | undefined
): TType | null | undefined
// return array of non-nullable if `fragmentType` is array of non-nullable
export function useFragment<TType>(
_documentNode: DocumentNode<TType, any>,
fragmentType: ReadonlyArray<FragmentType<DocumentNode<TType, any>>>
): ReadonlyArray<TType>
// return array of nullable if `fragmentType` is array of nullable
export function useFragment<TType>(
_documentNode: DocumentNode<TType, any>,
fragmentType:
| ReadonlyArray<FragmentType<DocumentNode<TType, any>>>
| null
| undefined
): ReadonlyArray<TType> | null | undefined
export function useFragment<TType>(
_documentNode: DocumentNode<TType, any>,
fragmentType:
| FragmentType<DocumentNode<TType, any>>
| ReadonlyArray<FragmentType<DocumentNode<TType, any>>>
| null
| undefined
): TType | ReadonlyArray<TType> | null | undefined {
return fragmentType as any
}
25 changes: 25 additions & 0 deletions examples/with-typescript-graphql/lib/gql/gql.ts
@@ -0,0 +1,25 @@
/* eslint-disable */
import * as types from './graphql'
import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'

const documents = {
'\n mutation UpdateName($name: String!) {\n updateName(name: $name) {\n id\n name\n status\n }\n }\n':
types.UpdateNameDocument,
'\n query Viewer {\n viewer {\n id\n name\n status\n }\n }\n':
types.ViewerDocument,
}

export function graphql(
source: '\n mutation UpdateName($name: String!) {\n updateName(name: $name) {\n id\n name\n status\n }\n }\n'
): typeof documents['\n mutation UpdateName($name: String!) {\n updateName(name: $name) {\n id\n name\n status\n }\n }\n']
export function graphql(
source: '\n query Viewer {\n viewer {\n id\n name\n status\n }\n }\n'
): typeof documents['\n query Viewer {\n viewer {\n id\n name\n status\n }\n }\n']

export function graphql(source: string): unknown
export function graphql(source: string) {
return (documents as any)[source] ?? {}
}

export type DocumentType<TDocumentNode extends DocumentNode<any, any>> =
TDocumentNode extends DocumentNode<infer TType, any> ? TType : never
136 changes: 136 additions & 0 deletions examples/with-typescript-graphql/lib/gql/graphql.ts
@@ -0,0 +1,136 @@
/* eslint-disable */
import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'
export type Maybe<T> = T | null
export type InputMaybe<T> = Maybe<T>
export type Exact<T extends { [key: string]: unknown }> = {
[K in keyof T]: T[K]
}
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & {
[SubKey in K]?: Maybe<T[SubKey]>
}
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & {
[SubKey in K]: Maybe<T[SubKey]>
}
/** All built-in and custom scalars, mapped to their actual values */
export type Scalars = {
ID: string
String: string
Boolean: boolean
Int: number
Float: number
}

export type Mutation = {
__typename?: 'Mutation'
updateName: User
}

export type MutationUpdateNameArgs = {
name: Scalars['String']
}

export type Query = {
__typename?: 'Query'
viewer: User
}

export type User = {
__typename?: 'User'
id: Scalars['ID']
name: Scalars['String']
status: Scalars['String']
}

export type UpdateNameMutationVariables = Exact<{
name: Scalars['String']
}>

export type UpdateNameMutation = {
__typename?: 'Mutation'
updateName: { __typename?: 'User'; id: string; name: string; status: string }
}

export type ViewerQueryVariables = Exact<{ [key: string]: never }>

export type ViewerQuery = {
__typename?: 'Query'
viewer: { __typename?: 'User'; id: string; name: string; status: string }
}

export const UpdateNameDocument = {
kind: 'Document',
definitions: [
{
kind: 'OperationDefinition',
operation: 'mutation',
name: { kind: 'Name', value: 'UpdateName' },
variableDefinitions: [
{
kind: 'VariableDefinition',
variable: { kind: 'Variable', name: { kind: 'Name', value: 'name' } },
type: {
kind: 'NonNullType',
type: {
kind: 'NamedType',
name: { kind: 'Name', value: 'String' },
},
},
},
],
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'Field',
name: { kind: 'Name', value: 'updateName' },
arguments: [
{
kind: 'Argument',
name: { kind: 'Name', value: 'name' },
value: {
kind: 'Variable',
name: { kind: 'Name', value: 'name' },
},
},
],
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: 'id' } },
{ kind: 'Field', name: { kind: 'Name', value: 'name' } },
{ kind: 'Field', name: { kind: 'Name', value: 'status' } },
],
},
},
],
},
},
],
} as unknown as DocumentNode<UpdateNameMutation, UpdateNameMutationVariables>
export const ViewerDocument = {
kind: 'Document',
definitions: [
{
kind: 'OperationDefinition',
operation: 'query',
name: { kind: 'Name', value: 'Viewer' },
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'Field',
name: { kind: 'Name', value: 'viewer' },
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: 'id' } },
{ kind: 'Field', name: { kind: 'Name', value: 'name' } },
{ kind: 'Field', name: { kind: 'Name', value: 'status' } },
],
},
},
],
},
},
],
} as unknown as DocumentNode<ViewerQuery, ViewerQueryVariables>
2 changes: 2 additions & 0 deletions examples/with-typescript-graphql/lib/gql/index.ts
@@ -0,0 +1,2 @@
export * from './gql'
export * from './fragment-masking'
15 changes: 7 additions & 8 deletions examples/with-typescript-graphql/package.json
@@ -1,17 +1,17 @@
{
"private": true,
"scripts": {
"codegen": "graphql-codegen -r ts-node/register",
"dev": "yarn codegen && next",
"build": "yarn codegen && next build",
"test": "yarn codegen && jest",
"codegen": "graphql-codegen -w",
"dev": "yarn graphql-codegen && next",
"build": "yarn graphql-codegen && next build",
"test": "yarn graphql-codegen && jest",
"start": "next start"
},
"dependencies": {
"@apollo/client": "^3.5.10",
"graphql-tag": "^2.12.6",
"@graphql-tools/load-files": "6.0.18",
"@graphql-yoga/node": "^2.2.1",
"graphql-yoga": "three",
"@graphql-tools/merge": "6.0.18",
"@graphql-tools/schema": "6.0.18",
"graphql": "15.6.0",
Expand All @@ -21,9 +21,8 @@
},
"devDependencies": {
"@graphql-codegen/typed-document-node": "^2.2.8",
"@graphql-codegen/cli": "^2.6.2",
"@graphql-codegen/typescript": "^2.4.8",
"@graphql-codegen/typescript-operations": "^2.3.5",
"@graphql-codegen/cli": "2.13.7",
"@graphql-codegen/client-preset": "1.1.0",
"@graphql-codegen/typescript-resolvers": "^2.6.1",
"@types/jest": "^27.0.2",
"@types/mocha": "^9.0.0",
Expand Down
22 changes: 13 additions & 9 deletions examples/with-typescript-graphql/pages/api/graphql.ts
@@ -1,16 +1,20 @@
import { createServer } from '@graphql-yoga/node'
import { createSchema, createYoga } from 'graphql-yoga'
import gql from 'graphql-tag'

import resolvers from 'lib/resolvers'
import typeDefs from 'lib/schema'
import { NextApiRequest, NextApiResponse } from 'next'

const server = createServer({
schema: {
typeDefs: gql(typeDefs),
resolvers,
},
endpoint: '/api/graphql',
// graphiql: false // uncomment to disable GraphiQL
const schema = createSchema({
typeDefs: gql(typeDefs),
resolvers,
})

export default server
export default createYoga<{
req: NextApiRequest
res: NextApiResponse
}>({
schema,
// Needed to be defined explicitly because our endpoint lives at a different path other than `/graphql`
graphqlEndpoint: '/api/graphql',
})

0 comments on commit f9fe62d

Please sign in to comment.