Skip to content

Commit

Permalink
more fixxxesss
Browse files Browse the repository at this point in the history
  • Loading branch information
n1ru4l committed Jul 29, 2022
1 parent e28277c commit ee9585a
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 11 deletions.
19 changes: 18 additions & 1 deletion examples/aws-lambda/lambda/graphql.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
import type { Handler } from '@aws-cdk/aws-lambda'
import { createYoga } from 'graphql-yoga'
import { createSchema } from 'graphql-yoga/schema'
import { configure } from '@vendia/serverless-express'

const app = createYoga()
const app = createYoga({
graphqlEndpoint: '/graphql',
landingPage: false,
schema: createSchema({
typeDefs: /* GraphQL */ `
type Query {
greetings: String
}
`,
resolvers: {
Query: {
greetings: () =>
'This is the `greetings` field of the root `Query` type',
},
},
}),
})

export const handler: Handler = configure({
app,
Expand Down
1 change: 1 addition & 0 deletions examples/aws-lambda/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"target": "ES2018",
"module": "commonjs",
Expand Down
14 changes: 14 additions & 0 deletions examples/azure-function/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AzureFunction, Context, HttpRequest } from '@azure/functions'
import { createYoga } from 'graphql-yoga'
import { createSchema } from 'graphql-yoga/schema'
import { Request } from '@whatwg-node/fetch'

const httpTrigger: AzureFunction = async function (
Expand All @@ -14,6 +15,19 @@ const httpTrigger: AzureFunction = async function (
warn: context.log.warn,
},
graphqlEndpoint: '/api/yoga',
schema: createSchema({
typeDefs: /* GraphQL */ `
type Query {
greetings: String
}
`,
resolvers: {
Query: {
greetings: () =>
'This is the `greetings` field of the root `Query` type',
},
},
}),
})
context.log('HTTP trigger function processed a request.')

Expand Down
5 changes: 3 additions & 2 deletions examples/cloudflare-advanced/src/index.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'

declare const EXAMPLE_KV: KVNamespace

const yoga = createYoga({
schema: {
schema: createSchema({
typeDefs: /* GraphQL */ `
scalar File
scalar JSON
Expand Down Expand Up @@ -99,7 +100,7 @@ const yoga = createYoga({
},
},
},
},
}),
})

self.addEventListener('fetch', yoga)
19 changes: 18 additions & 1 deletion examples/cloudflare-modules/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
// src/index.mjs
import { createYoga } from 'graphql-yoga'
import { createSchema } from 'graphql-yoga/schema'

export default createYoga()
export default createYoga({
graphqlEndpoint: '/graphql',
landingPage: false,
schema: createSchema({
typeDefs: /* GraphQL */ `
type Query {
greetings: String
}
`,
resolvers: {
Query: {
greetings: () =>
'This is the `greetings` field of the root `Query` type',
},
},
}),
})
14 changes: 14 additions & 0 deletions examples/nextjs/pages/api/graphql.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import { createYoga } from 'graphql-yoga'
import { createSchema } from 'graphql-yoga/schema'
import type { NextApiRequest, NextApiResponse } from 'next'

// Docs: https://vercel.com/docs/concepts/functions/serverless-functions
Expand All @@ -16,4 +17,17 @@ export default createYoga<{
res: NextApiResponse
}>({
graphqlEndpoint: '/api/graphql',
schema: createSchema({
typeDefs: /* GraphQL */ `
type Query {
greetings: String
}
`,
resolvers: {
Query: {
greetings: () =>
'This is the `greetings` field of the root `Query` type',
},
},
}),
})
4 changes: 2 additions & 2 deletions examples/node-esm/yoga.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ export const yoga = createYoga({
schema: createSchema({
typeDefs: /* GraphQL */ `
type Query {
hello: String
greetings: String
}
`,
resolvers: {
Query: {
hello: () => 'Hello world!',
greetings: () => 'Hello world!',
},
},
}),
Expand Down
15 changes: 13 additions & 2 deletions examples/service-worker/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createYoga } from 'graphql-yoga'
import { createSchema } from 'graphql-yoga/schema'
import { Repeater } from 'graphql-yoga/subscription'

// We can define GraphQL Route dynamically using env vars.
declare var GRAPHQL_ROUTE: string
Expand All @@ -9,13 +10,23 @@ const yoga = createYoga({
schema: createSchema({
typeDefs: /* GraphQL */ `
type Query {
hello: String
greetings: String
time: String
}
`,
resolvers: {
Query: {
hello: () => 'Hello World!',
greetings: () =>
'This is the `greetings` field of the root `Query` type',
},
Subscription: () =>
new Repeater(async (push, end) => {
const getTime = () => new Date().toISOString()
push(getTime())
const interval = setInterval(() => push(getTime()), 1000)
end.then(() => clearInterval(interval))
await end
}),
},
}),
})
Expand Down
18 changes: 16 additions & 2 deletions packages/plugins/apq/tests/automatic-persisted-queries.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { createYoga, YogaServerInstance } from 'graphql-yoga'
import { createYoga } from 'graphql-yoga'
import { createSchema } from 'graphql-yoga/schema'

import request from 'supertest'
import { createInMemoryAPQStore, useAPQ } from '../src'
import { createInMemoryAPQStore, useAPQ } from '@graphql-yoga/plugin-apq'

const schema = createSchema({
typeDefs: /* GraphQL */ `
type Query {
_: String
}
`,
})

describe('Automatic Persisted Queries', () => {
it('should return not found error if persisted query is missing', async () => {
Expand All @@ -11,6 +21,7 @@ describe('Automatic Persisted Queries', () => {
store,
}),
],
schema,
})
const response = await request(yoga)
.post('/graphql')
Expand All @@ -36,6 +47,7 @@ describe('Automatic Persisted Queries', () => {
store,
}),
],
schema,
})
const persistedQueryEntry = {
version: 1,
Expand Down Expand Up @@ -63,6 +75,7 @@ describe('Automatic Persisted Queries', () => {
store,
}),
],
schema,
})

const persistedQueryEntry = {
Expand Down Expand Up @@ -95,6 +108,7 @@ describe('Automatic Persisted Queries', () => {
store,
}),
],
schema,
})
const query = `{__typename}`
const response = await request(yoga)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { createYoga } from 'graphql-yoga'
import { createSchema } from 'graphql-yoga/schema'
import request from 'supertest'
import { usePersistedOperations } from '../src'
import { usePersistedOperations } from '@graphql-yoga/plugin-persisted-operations'

const schema = createSchema({
typeDefs: /* GraphQL */ `
type Query {
_: String
}
`,
})

describe('Automatic Persisted Queries', () => {
it('should return not found error if persisted query is missing', async () => {
Expand All @@ -11,6 +20,7 @@ describe('Automatic Persisted Queries', () => {
store,
}),
],
schema,
})
const response = await request(yoga)
.post('/graphql')
Expand All @@ -36,6 +46,7 @@ describe('Automatic Persisted Queries', () => {
store,
}),
],
schema,
})
const persistedQueryEntry = {
version: 1,
Expand Down Expand Up @@ -64,6 +75,7 @@ describe('Automatic Persisted Queries', () => {
store,
}),
],
schema,
})
const persistedQueryEntry = {
version: 1,
Expand All @@ -90,6 +102,7 @@ describe('Automatic Persisted Queries', () => {
allowArbitraryOperations: true,
}),
],
schema,
})
const persistedQueryEntry = {
version: 1,
Expand Down Expand Up @@ -117,6 +130,7 @@ describe('Automatic Persisted Queries', () => {
request.headers.get('foo') === 'bar',
}),
],
schema,
})
const persistedQueryEntry = {
version: 1,
Expand Down
11 changes: 11 additions & 0 deletions packages/plugins/response-cache/__tests__/response-cache.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { createYoga } from 'graphql-yoga'
import { createSchema } from 'graphql-yoga/schema'
import { useResponseCache } from '@graphql-yoga/plugin-response-cache'

const schema = createSchema({
typeDefs: /* GraphQL */ `
type Query {
_: String
}
`,
})

it('cache a query operation', async () => {
const yoga = createYoga({
plugins: [
Expand All @@ -9,6 +18,7 @@ it('cache a query operation', async () => {
includeExtensionMetadata: true,
}),
],
schema,
})
function fetch() {
return yoga.fetch('http://localhost:3000/graphql', {
Expand Down Expand Up @@ -60,6 +70,7 @@ it('cache a query operation per session', async () => {
includeExtensionMetadata: true,
}),
],
schema,
})
function fetch(sessionId: string) {
return yoga.fetch('http://localhost:3000/graphql', {
Expand Down

0 comments on commit ee9585a

Please sign in to comment.