Skip to content

Commit

Permalink
export handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan authored and n1ru4l committed Jul 29, 2022
1 parent c4b3a9c commit e28277c
Show file tree
Hide file tree
Showing 81 changed files with 399 additions and 243 deletions.
11 changes: 11 additions & 0 deletions examples/apollo-federation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Apollo Federation Example

Run Apollo Federation Subgraphs and Gateways using GraphQL Yoga.

Start Gateway and Services:

```bash
yarn start
```

Then visit `http://localhost:4000`
2 changes: 1 addition & 1 deletion examples/apollo-federation/gateway/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ async function main() {
// Initialize the gateway
const gateway = new ApolloGateway({
serviceList: [
{ name: 'accounts', url: 'http://localhost:4001' },
{ name: 'accounts', url: 'http://localhost:4001/graphql' },
// ...additional subgraphs...
],
})
Expand Down
2 changes: 1 addition & 1 deletion examples/apollo-federation/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "apollo-federation-with-yoga",
"name": "example-apollo-federation",
"version": "0.0.1",
"private": true,
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions examples/apollo-federation/service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const yoga = createYoga({
})

const server = createServer(yoga)

server.listen(4001, () => {
console.log(`🚀 Server ready at http://localhost:4001`)
})
2 changes: 1 addition & 1 deletion examples/aws-lambda/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "aws-lambda",
"name": "example-aws-lambda",
"private": true,
"version": "0.0.0",
"bin": {
Expand Down
2 changes: 1 addition & 1 deletion examples/azure-function/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "azure-function",
"name": "example-azure-function",
"version": "0.0.0",
"private": true,
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion examples/cloudflare-advanced/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "cloudflare-advanced",
"name": "example-cloudflare-advanced",
"version": "0.7.3",
"private": true,
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion examples/cloudflare-modules/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "cloudflare",
"name": "example-cloudflare-modules",
"version": "0.4.3",
"private": true,
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion examples/defer-stream/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "defer-stream-example",
"name": "example-defer-stream",
"private": true,
"version": "0.13.4",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion examples/error-handling/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "error-masking-example",
"name": "example-error-handling",
"private": true,
"version": "0.13.4",
"scripts": {
Expand Down
5 changes: 3 additions & 2 deletions examples/error-handling/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createYoga } from 'graphql-yoga'
import { createSchema } from 'graphql-yoga/schema'
import { fetch } from '@whatwg-node/fetch'
import { GraphQLError } from 'graphql'
import { createServer } from 'http'
Expand All @@ -20,7 +21,7 @@ const users = [

// Provide your schema
const yoga = createYoga({
schema: {
schema: createSchema({
typeDefs: /* GraphQL */ `
type User {
id: ID!
Expand Down Expand Up @@ -58,7 +59,7 @@ const yoga = createYoga({
},
},
},
},
}),
logging: true,
maskedErrors: true,
})
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion examples/express/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "express-example",
"name": "example-express",
"private": true,
"version": "0.13.4",
"scripts": {
Expand Down
5 changes: 3 additions & 2 deletions examples/express/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { createYoga } from 'graphql-yoga'
import { createSchema } from 'graphql-yoga/schema'
import express from 'express'

export function buildApp(app: ReturnType<typeof express>) {
const graphQLServer = createYoga({
schema: {
schema: createSchema({
typeDefs: /* GraphQL */ `
scalar File
type Query {
Expand Down Expand Up @@ -34,7 +35,7 @@ export function buildApp(app: ReturnType<typeof express>) {
},
},
},
},
}),
logging: false,
})

Expand Down
2 changes: 1 addition & 1 deletion examples/fastify-modules/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "fastify-modules-example",
"name": "example-fastify-modules",
"private": true,
"version": "0.13.4",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion examples/fastify-modules/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import fastify, {
} from 'fastify'
import { useGraphQLModules } from '@envelop/graphql-modules'
import { createApplication } from 'graphql-modules'
import { basicModule } from './modules/basic.js'
import { basicModule } from './modules/basic'

export function createGraphQLApp() {
return createApplication({
Expand Down
2 changes: 1 addition & 1 deletion examples/fastify-modules/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { buildApp } from './app.js'
import { buildApp } from './app'

const app = buildApp()

Expand Down
4 changes: 2 additions & 2 deletions examples/fastify-modules/src/modules/basic/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { createModule } from 'graphql-modules'
import { join } from 'path'
import { loadFilesSync } from '@graphql-tools/load-files'
import { resolvers } from './resolvers.js'
import { BasicProvider } from './providers.js'
import { resolvers } from './resolvers'
import { BasicProvider } from './providers'

export const basicModule = createModule({
id: 'basic',
Expand Down
2 changes: 1 addition & 1 deletion examples/fastify-modules/src/modules/basic/resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BasicProvider } from './providers.js'
import { BasicProvider } from './providers'

export const resolvers = {
Query: {
Expand Down
2 changes: 1 addition & 1 deletion examples/fastify/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "fastify-example",
"name": "example-fastify",
"private": true,
"version": "0.13.4",
"scripts": {
Expand Down
5 changes: 3 additions & 2 deletions examples/fastify/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createYoga } from 'graphql-yoga'
import fastify, { FastifyReply, FastifyRequest } from 'fastify'
import { createSchema } from 'graphql-yoga/schema'

export function buildApp(logging = true) {
const app = fastify({
Expand All @@ -15,7 +16,7 @@ export function buildApp(logging = true) {
req: FastifyRequest
reply: FastifyReply
}>({
schema: {
schema: createSchema({
typeDefs: /* GraphQL */ `
scalar File
Expand Down Expand Up @@ -53,7 +54,7 @@ export function buildApp(logging = true) {
},
},
},
},
}),
// Integrate Fastify Logger to Yoga
logging: {
debug: (...args) => args.forEach((arg) => app.log.debug(arg)),
Expand Down
2 changes: 1 addition & 1 deletion examples/fastify/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { buildApp } from './app.js'
import { buildApp } from './app'

const app = buildApp(true)

Expand Down
1 change: 1 addition & 0 deletions examples/file-upload-nextjs-pothos/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.next
2 changes: 1 addition & 1 deletion examples/file-upload-nextjs-pothos/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "file-upload-nextjs-pothos",
"name": "example-file-upload-nextjs-pothos",
"private": true,
"version": "0.11.4",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions examples/file-upload-nextjs-pothos/pages/api/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ export default createYoga<{
res: NextApiResponse
}>({
schema,
graphqlEndpoint: '/api/graphql',
})
3 changes: 2 additions & 1 deletion examples/file-upload-nextjs-pothos/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve"
"jsx": "preserve",
"incremental": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
Expand Down
2 changes: 1 addition & 1 deletion examples/file-upload-nexus/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "file-upload-nexus",
"name": "example-file-upload-nexus",
"private": true,
"version": "0.13.4",
"scripts": {
Expand Down
5 changes: 3 additions & 2 deletions examples/file-upload/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { createYoga } from 'graphql-yoga'
import { createSchema } from 'graphql-yoga/schema'
import http from 'http'
import fs from 'fs'
import path from 'path'

const yoga = createYoga({
schema: {
schema: createSchema({
typeDefs: /* GraphQL */ `
scalar File
type Query {
Expand Down Expand Up @@ -38,7 +39,7 @@ const yoga = createYoga({
},
},
},
},
}),
graphiql: {
title: 'Hello World',
},
Expand Down
2 changes: 1 addition & 1 deletion examples/file-upload/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "file-upload",
"name": "example-file-upload",
"private": true,
"version": "0.13.4",
"scripts": {
Expand Down
5 changes: 3 additions & 2 deletions examples/generic-auth/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createYoga, YogaInitialContext } from 'graphql-yoga'
import { createSchema } from 'graphql-yoga/schema'
import { useGenericAuth } from '@envelop/generic-auth'
import { createServer } from 'http'

Expand Down Expand Up @@ -40,7 +41,7 @@ const yoga = createYoga<{}, { currentUser: User }>({
},
}),
],
schema: {
schema: createSchema({
typeDefs: /* GraphQL */ `
directive @auth on FIELD_DEFINITION
Expand Down Expand Up @@ -74,7 +75,7 @@ const yoga = createYoga<{}, { currentUser: User }>({
},
},
},
},
}),
})

const server = createServer(yoga)
Expand Down
2 changes: 1 addition & 1 deletion examples/graphql-config/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "graphql-config-example",
"name": "example-graphql-config",
"private": true,
"version": "0.13.4",
"scripts": {
Expand Down
10 changes: 5 additions & 5 deletions examples/graphql-ws/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"name": "graphql-ws",
"name": "example-graphql-ws",
"private": true,
"version": "0.10.4",
"scripts": {
"start": "ts-node src/index.ts",
"check": "tsc --pretty --noEmit"
},
"dependencies": {
"graphql-yoga": "2.13.4",
"graphql": "16.5.0",
"graphql-ws": "0.10.4",
"ws": "8.8.1"
"graphql-yoga": "^2.13.4",
"graphql": "^16.5.0",
"graphql-ws": "^5.9.1",
"ws": "^8.8.1"
},
"devDependencies": {
"ts-node": "10.9.1",
Expand Down
40 changes: 36 additions & 4 deletions examples/graphql-ws/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { createYoga } from 'graphql-yoga'
import { createSchema } from 'graphql-yoga/schema'
import { Repeater } from 'graphql-yoga/subscription'
import { createServer } from 'http'
import { WebSocketServer } from 'ws'
import { useServer } from 'graphql-ws/lib/use/ws'
Expand All @@ -8,27 +10,55 @@ async function main() {
graphiql: {
subscriptionsProtocol: 'WS',
},
schema: createSchema({
typeDefs: /* GraphQL */ `
type Query {
hello: String!
}
type Subscription {
currentTime: String
}
`,
resolvers: {
Query: {
hello: () => 'Hi there.',
},
Subscription: {
currentTime: {
subscribe: () =>
new Repeater(async (push, end) => {
const interval = setInterval(() => {
console.log('Publish new time')
push({ currentTime: new Date().toISOString() })
}, 1000)
end.then(() => clearInterval(interval))
await end
}),
},
},
},
}),
})

const httpServer = createServer(yogaApp)
const wsServer = new WebSocketServer({
server: httpServer,
path: yogaApp.getAddressInfo().endpoint,
path: '/graphql',
})

useServer(
{
execute: (args: any) => args.rootValue.execute(args),
subscribe: (args: any) => args.rootValue.subscribe(args),
onSubscribe: async (ctx, msg) => {
onSubscribe: async (context, msg) => {
const { schema, execute, subscribe, contextFactory, parse, validate } =
yogaApp.getEnveloped(ctx)
yogaApp.getEnveloped(context)
const args = {
schema,
operationName: msg.payload.operationName,
document: parse(msg.payload.query),
variableValues: msg.payload.variables,
contextValue: await contextFactory(),
contextValue: await contextFactory(context),
rootValue: {
execute,
subscribe,
Expand All @@ -42,6 +72,8 @@ async function main() {
},
wsServer,
)

httpServer.listen(4000)
}

main().catch((e) => {
Expand Down
Loading

0 comments on commit e28277c

Please sign in to comment.