Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
04c99067
Unverified
Commit
04c99067
authored
Aug 30, 2020
by
Soichi Takamura
Committed by
GitHub
Aug 30, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update with-typescript-graphql (#16101)
parent
624b748d
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
139 additions
and
43 deletions
+139
-43
.babelrc
examples/with-typescript-graphql/.babelrc
+3
-0
.gitignore
examples/with-typescript-graphql/.gitignore
+2
-1
.graphql-let.yml
examples/with-typescript-graphql/.graphql-let.yml
+3
-2
jest.config.js
examples/with-typescript-graphql/jest.config.js
+13
-0
apollo.ts
examples/with-typescript-graphql/lib/apollo.ts
+7
-4
partial.graphql
examples/with-typescript-graphql/lib/partial.graphql
+4
-0
schema.ts
examples/with-typescript-graphql/lib/schema.ts
+8
-2
type-defs.graphqls
examples/with-typescript-graphql/lib/type-defs.graphqls
+0
-6
user.graphqls
examples/with-typescript-graphql/lib/user.graphqls
+5
-0
viewer.graphql
examples/with-typescript-graphql/lib/viewer.graphql
+3
-2
next-env.d.ts
examples/with-typescript-graphql/next-env.d.ts
+2
-0
next.config.js
examples/with-typescript-graphql/next.config.js
+7
-1
package.json
examples/with-typescript-graphql/package.json
+22
-22
_app.tsx
examples/with-typescript-graphql/pages/_app.tsx
+1
-1
index.tsx
examples/with-typescript-graphql/pages/index.tsx
+1
-2
index.test.tsx.snap
...typescript-graphql/test/__snapshots__/index.test.tsx.snap
+21
-0
index.test.tsx
examples/with-typescript-graphql/test/index.test.tsx
+37
-0
No files found.
examples/with-typescript-graphql/.babelrc
0 → 100644
View file @
04c99067
{
"presets": ["next/babel"]
}
examples/with-typescript-graphql/.gitignore
View file @
04c99067
...
@@ -33,6 +33,7 @@ yarn-error.log*
...
@@ -33,6 +33,7 @@ yarn-error.log*
# vercel
# vercel
.vercel
.vercel
# graphql
# graphql-let
__generated__
*.graphql.d.ts
*.graphql.d.ts
*.graphqls.d.ts
*.graphqls.d.ts
examples/with-typescript-graphql/.graphql-let.yml
View file @
04c99067
schema
:
lib/type-defs.graphqls
schema
:
'
**/*.graphqls'
schemaEntrypoint
:
'
lib/type-defs.graphqls'
documents
:
'
**/*.graphql'
documents
:
'
**/*.graphql'
plugins
:
plugins
:
-
typescript
-
typescript
-
typescript-operations
-
typescript-operations
-
typescript-react-apollo
-
typescript-react-apollo
respectGitIgnore
:
true
cacheDir
:
__generated__
examples/with-typescript-graphql/jest.config.js
0 → 100644
View file @
04c99067
module
.
exports
=
{
roots
:
[
'<rootDir>'
],
moduleFileExtensions
:
[
'js'
,
'ts'
,
'tsx'
,
'json'
],
testPathIgnorePatterns
:
[
'<rootDir>[/
\\\\
](node_modules|.next)[/
\\\\
]'
],
transformIgnorePatterns
:
[
'[/
\\\\
]node_modules[/
\\\\
].+
\\
.(ts|tsx)$'
],
transform
:
{
'^.+
\\
.(ts|tsx)$'
:
'babel-jest'
,
'
\\
.graphql$'
:
[
'graphql-let/jestTransformer'
,
{
subsequentTransformer
:
'babel-jest'
},
],
},
}
examples/with-typescript-graphql/lib/apollo.ts
View file @
04c99067
import
{
IncomingMessage
,
ServerResponse
}
from
'http'
import
{
IncomingMessage
,
ServerResponse
}
from
'http'
import
{
useMemo
}
from
'react'
import
{
useMemo
}
from
'react'
import
{
ApolloClient
}
from
'apollo-client'
import
{
import
{
InMemoryCache
,
NormalizedCacheObject
}
from
'apollo-cache-inmemory'
ApolloClient
,
InMemoryCache
,
NormalizedCacheObject
,
}
from
'@apollo/client'
let
apolloClient
:
ApolloClient
<
NormalizedCacheObject
>
|
undefined
let
apolloClient
:
ApolloClient
<
NormalizedCacheObject
>
|
undefined
...
@@ -12,11 +15,11 @@ export type ResolverContext = {
...
@@ -12,11 +15,11 @@ export type ResolverContext = {
function
createIsomorphLink
(
context
:
ResolverContext
=
{})
{
function
createIsomorphLink
(
context
:
ResolverContext
=
{})
{
if
(
typeof
window
===
'undefined'
)
{
if
(
typeof
window
===
'undefined'
)
{
const
{
SchemaLink
}
=
require
(
'
apollo-link-
schema'
)
const
{
SchemaLink
}
=
require
(
'
@apollo/client/link/
schema'
)
const
{
schema
}
=
require
(
'./schema'
)
const
{
schema
}
=
require
(
'./schema'
)
return
new
SchemaLink
({
schema
,
context
})
return
new
SchemaLink
({
schema
,
context
})
}
else
{
}
else
{
const
{
HttpLink
}
=
require
(
'
apollo-link-http
'
)
const
{
HttpLink
}
=
require
(
'
@apollo/client
'
)
return
new
HttpLink
({
return
new
HttpLink
({
uri
:
'/api/graphql'
,
uri
:
'/api/graphql'
,
credentials
:
'same-origin'
,
credentials
:
'same-origin'
,
...
...
examples/with-typescript-graphql/lib/partial.graphql
0 → 100644
View file @
04c99067
fragment
Partial
on
User
{
id
name
}
examples/with-typescript-graphql/lib/schema.ts
View file @
04c99067
import
{
makeExecutableSchema
}
from
'graphql-tools'
import
{
join
}
from
'path'
import
typeDefs
from
'./type-defs.graphqls'
import
{
makeExecutableSchema
}
from
'@graphql-tools/schema'
import
{
loadFilesSync
}
from
'@graphql-tools/load-files'
import
{
mergeTypeDefs
}
from
'@graphql-tools/merge'
import
graphQLLetConfig
from
'../.graphql-let.yml'
import
resolvers
from
'./resolvers'
import
resolvers
from
'./resolvers'
const
loadedFiles
=
loadFilesSync
(
join
(
process
.
cwd
(),
graphQLLetConfig
.
schema
))
const
typeDefs
=
mergeTypeDefs
(
loadedFiles
)
export
const
schema
=
makeExecutableSchema
({
export
const
schema
=
makeExecutableSchema
({
typeDefs
,
typeDefs
,
resolvers
,
resolvers
,
...
...
examples/with-typescript-graphql/lib/type-defs.graphqls
View file @
04c99067
type User {
id: ID!
name: String!
status: String!
}
type Query {
type Query {
viewer: User!
viewer: User!
}
}
examples/with-typescript-graphql/lib/user.graphqls
0 → 100644
View file @
04c99067
type User {
id: ID!
name: String!
status: String!
}
examples/with-typescript-graphql/lib/viewer.graphql
View file @
04c99067
# import Partial from './partial.graphql'
query
Viewer
{
query
Viewer
{
viewer
{
viewer
{
id
...
Partial
name
status
status
}
}
}
}
examples/with-typescript-graphql/next-env.d.ts
View file @
04c99067
...
@@ -5,3 +5,5 @@ declare module '*.graphqls' {
...
@@ -5,3 +5,5 @@ declare module '*.graphqls' {
import
{
DocumentNode
}
from
'graphql'
import
{
DocumentNode
}
from
'graphql'
export
default
typeof
DocumentNode
export
default
typeof
DocumentNode
}
}
declare
module
'*.yml'
examples/with-typescript-graphql/next.config.js
View file @
04c99067
...
@@ -9,7 +9,13 @@ module.exports = {
...
@@ -9,7 +9,13 @@ module.exports = {
config
.
module
.
rules
.
push
({
config
.
module
.
rules
.
push
({
test
:
/
\.
graphqls$/
,
test
:
/
\.
graphqls$/
,
exclude
:
/node_modules/
,
exclude
:
/node_modules/
,
use
:
[
'graphql-tag/loader'
,
'graphql-let/schema/loader'
],
use
:
[
'graphql-let/schema/loader'
],
})
config
.
module
.
rules
.
push
({
test
:
/
\.
ya
?
ml$/
,
type
:
'json'
,
use
:
'yaml-loader'
,
})
})
return
config
return
config
...
...
examples/with-typescript-graphql/package.json
View file @
04c99067
...
@@ -7,36 +7,36 @@
...
@@ -7,36 +7,36 @@
"codegen"
:
"graphql-let"
,
"codegen"
:
"graphql-let"
,
"dev"
:
"yarn codegen && next"
,
"dev"
:
"yarn codegen && next"
,
"build"
:
"yarn codegen && next build"
,
"build"
:
"yarn codegen && next build"
,
"test"
:
"yarn codegen && jest"
,
"start"
:
"next start"
"start"
:
"next start"
},
},
"dependencies"
:
{
"dependencies"
:
{
"@apollo/react-common"
:
"3.1.4"
,
"@apollo/client"
:
"^3.1.3"
,
"@apollo/react-components"
:
"^3.1.5"
,
"@graphql-tools/load-files"
:
"6.0.18"
,
"@apollo/react-hooks"
:
"3.1.5"
,
"@graphql-tools/merge"
:
"6.0.18"
,
"apollo-cache"
:
"^1.3.5"
,
"@graphql-tools/schema"
:
"6.0.18"
,
"apollo-cache-inmemory"
:
"^1.6.6"
,
"apollo-server-micro"
:
"^2.16.1"
,
"apollo-client"
:
"^2.6.10"
,
"graphql"
:
"15.3.0"
,
"apollo-link"
:
"1.2.14"
,
"apollo-link-http"
:
"1.5.17"
,
"apollo-link-schema"
:
"1.2.5"
,
"apollo-server-micro"
:
"^2.14.2"
,
"apollo-utilities"
:
"^1.3.3"
,
"graphql"
:
"^14.6.0"
,
"graphql-tag"
:
"^2.10.3"
,
"next"
:
"latest"
,
"next"
:
"latest"
,
"react"
:
"^16.13.1"
,
"react"
:
"^16.13.1"
,
"react-dom"
:
"^16.13.1"
"react-dom"
:
"^16.13.1"
},
},
"devDependencies"
:
{
"devDependencies"
:
{
"@graphql-codegen/cli"
:
"^1.15.1"
,
"@graphql-codegen/cli"
:
"^1.17.8"
,
"@graphql-codegen/plugin-helpers"
:
"^1.15.1"
,
"@graphql-codegen/plugin-helpers"
:
"^1.17.8"
,
"@graphql-codegen/typescript"
:
"^1.13.3"
,
"@graphql-codegen/typescript"
:
"^1.17.8"
,
"@graphql-codegen/typescript-operations"
:
"^1.13.3"
,
"@graphql-codegen/typescript-operations"
:
"^1.17.8"
,
"@graphql-codegen/typescript-react-apollo"
:
"^1.13.3"
,
"@graphql-codegen/typescript-react-apollo"
:
"^2.0.6"
,
"@graphql-codegen/typescript-resolvers"
:
"^1.15.1"
,
"@graphql-codegen/typescript-resolvers"
:
"^1.17.8"
,
"@types/react"
:
"^16.9.34"
,
"@types/react"
:
"^16.9.46"
,
"@types/react-dom"
:
"^16.9.7"
,
"@types/react-dom"
:
"^16.9.8"
,
"@types/react-test-renderer"
:
"16.9.3"
,
"babel-jest"
:
"26.3.0"
,
"graphql-let"
:
"0.x"
,
"graphql-let"
:
"0.x"
,
"typescript"
:
"^3.8.3"
"graphql-tag"
:
"2.11.0"
,
"jest"
:
"26.4.0"
,
"react-test-renderer"
:
"16.13.1"
,
"typescript"
:
"^3.9.7"
,
"yaml-loader"
:
"0.6.0"
}
}
}
}
examples/with-typescript-graphql/pages/_app.tsx
View file @
04c99067
import
{
AppProps
}
from
'next/app'
import
{
AppProps
}
from
'next/app'
import
{
ApolloProvider
}
from
'@apollo/
react-hooks
'
import
{
ApolloProvider
}
from
'@apollo/
client
'
import
{
useApollo
}
from
'../lib/apollo'
import
{
useApollo
}
from
'../lib/apollo'
export
default
function
App
({
Component
,
pageProps
}:
AppProps
)
{
export
default
function
App
({
Component
,
pageProps
}:
AppProps
)
{
...
...
examples/with-typescript-graphql/pages/index.tsx
View file @
04c99067
...
@@ -3,8 +3,7 @@ import { useViewerQuery, ViewerDocument } from '../lib/viewer.graphql'
...
@@ -3,8 +3,7 @@ import { useViewerQuery, ViewerDocument } from '../lib/viewer.graphql'
import
{
initializeApollo
}
from
'../lib/apollo'
import
{
initializeApollo
}
from
'../lib/apollo'
const
Index
=
()
=>
{
const
Index
=
()
=>
{
const
{
data
}
=
useViewerQuery
()
const
{
viewer
}
=
useViewerQuery
().
data
!
const
{
viewer
}
=
data
!
return
(
return
(
<
div
>
<
div
>
...
...
examples/with-typescript-graphql/test/__snapshots__/index.test.tsx.snap
0 → 100644
View file @
04c99067
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Index renders the html we want 1`] = `
<div>
You're signed in as
Baa
and you're
Healthy
go to the
<a
href="/about"
onClick={[Function]}
onMouseEnter={[Function]}
>
about
</a>
page.
</div>
`;
examples/with-typescript-graphql/test/index.test.tsx
0 → 100644
View file @
04c99067
import
{
InMemoryCache
,
gql
}
from
'@apollo/client'
import
React
from
'react'
import
Index
from
'../pages'
import
renderer
from
'react-test-renderer'
import
{
MockedProvider
}
from
'@apollo/client/testing'
const
cache
=
new
InMemoryCache
()
cache
.
writeQuery
({
query
:
gql
`
query Viewer {
viewer {
id
name
status
}
}
`
,
data
:
{
viewer
:
{
__typename
:
'User'
,
id
:
'Baa'
,
name
:
'Baa'
,
status
:
'Healthy'
,
},
},
})
describe
(
'Index'
,
()
=>
{
it
(
'renders the html we want'
,
async
()
=>
{
const
component
=
renderer
.
create
(
<
MockedProvider
cache=
{
cache
}
>
<
Index
/>
</
MockedProvider
>
)
expect
(
component
.
toJSON
()).
toMatchSnapshot
()
})
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment