Skip to content

Commit

Permalink
feat: tree-shake ability of all modules (#1472)
Browse files Browse the repository at this point in the history
* export handling

* more fixxxesss

* Gooo

* fix: test

* extend extend extend

* Fix CF example

* Fix types

* Some fixes

* do not use exports map :)

* fix: skip lb check

* skip lib checks

* adjust import

* chore: update typescript output dir

Co-authored-by: Arda TANRIKULU <ardatanrikulu@gmail.com>
  • Loading branch information
n1ru4l and ardatan committed Aug 9, 2022
1 parent a28d6a3 commit 9ca0def
Show file tree
Hide file tree
Showing 123 changed files with 629 additions and 525 deletions.
3 changes: 0 additions & 3 deletions bob.config.js

This file was deleted.

3 changes: 2 additions & 1 deletion e2e/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"moduleResolution": "node",
"declaration": true,
"sourceMap": true,
"resolveJsonModule": true
"resolveJsonModule": true,
"skipLibCheck": true
},
"include": ["./**/*.ts"]
}
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`)
})
20 changes: 18 additions & 2 deletions examples/aws-lambda/lambda/graphql.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
import type { Handler } from '@aws-cdk/aws-lambda'
import { createYoga } from 'graphql-yoga'
import { createYoga, createSchema } from 'graphql-yoga'
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
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
15 changes: 14 additions & 1 deletion examples/azure-function/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AzureFunction, Context, HttpRequest } from '@azure/functions'
import { createYoga } from 'graphql-yoga'
import { createYoga, createSchema } from 'graphql-yoga'
import { Request } from '@whatwg-node/fetch'

const httpTrigger: AzureFunction = async function (
Expand All @@ -14,6 +14,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
3 changes: 1 addition & 2 deletions examples/cloudflare-advanced/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
worker/
wrangler.toml
worker/
4 changes: 2 additions & 2 deletions 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 All @@ -12,7 +12,7 @@
"graphql": "16.5.0"
},
"devDependencies": {
"@cloudflare/wrangler": "1.19.12",
"wrangler": "2.0.23",
"typescript": "4.7.4",
"ts-loader": "9.3.1",
"webpack": "5.74.0"
Expand Down
43 changes: 21 additions & 22 deletions examples/cloudflare-advanced/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { createYoga } from 'graphql-yoga'
import { createYoga, createSchema, Repeater } from 'graphql-yoga'

declare const EXAMPLE_KV: KVNamespace

const yoga = createYoga({
schema: {
schema: createSchema({
typeDefs: /* GraphQL */ `
scalar File
scalar JSON
Expand Down Expand Up @@ -74,32 +74,31 @@ const yoga = createYoga({
},
Subscription: {
time: {
async *subscribe() {
while (true) {
yield { time: new Date().toISOString() }
await new Promise((resolve) => setTimeout(resolve, 1000))
}
},
subscribe: () =>
new Repeater((push, end) => {
const interval = setInterval(
() => push(new Date().toISOString()),
1000,
)
end.then(() => clearInterval(interval))
}),
resolve: (value) => value,
},
scheduled: {
async *subscribe() {
let scheduledEvent: Event
addEventListener('scheduled', (event) => {
scheduledEvent = event
})
while (true) {
if (scheduledEvent) {
const event = scheduledEvent
scheduledEvent = undefined
yield event
}
}
},
subscribe: () =>
new Repeater((push, end) => {
const eventListener = (event: ScheduledEvent) => push(event)
self.addEventListener('scheduled', eventListener)
end.then(() =>
self.removeEventListener('scheduled', eventListener),
)
}),
resolve: (event) => event,
},
},
},
},
}),
maskedErrors: false,
})

self.addEventListener('fetch', yoga)
23 changes: 0 additions & 23 deletions examples/cloudflare-advanced/webpack.config.js

This file was deleted.

6 changes: 6 additions & 0 deletions examples/cloudflare-advanced/wrangler.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
compatibility_date = "2022-02-21"
name = "graphql-yoga"
account_id = ""
workers_dev = true
main = "src/index.ts"
compatibility_flags = ["streams_enable_constructors"]
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
20 changes: 18 additions & 2 deletions examples/cloudflare-modules/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
// src/index.mjs
import { createYoga } from 'graphql-yoga'
import { createYoga, createSchema } from 'graphql-yoga'

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',
},
},
}),
})
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/defer-stream/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"skipLibCheck": true,
"target": "esnext",
"moduleResolution": "node",
"module": "commonjs",
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
6 changes: 3 additions & 3 deletions examples/error-handling/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createYoga } from 'graphql-yoga'
import { createYoga, createSchema } from 'graphql-yoga'
import { fetch } from '@whatwg-node/fetch'
import { GraphQLError } from 'graphql'
import { createServer } from 'http'
Expand All @@ -20,7 +20,7 @@ const users = [

// Provide your schema
const yoga = createYoga({
schema: {
schema: createSchema({
typeDefs: /* GraphQL */ `
type User {
id: ID!
Expand Down Expand Up @@ -58,7 +58,7 @@ const yoga = createYoga({
},
},
},
},
}),
logging: true,
maskedErrors: true,
})
Expand Down
2 changes: 1 addition & 1 deletion examples/error-handling/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"skipLibCheck": true,
"target": "esnext",
"moduleResolution": "node",
"module": "commonjs",
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
6 changes: 3 additions & 3 deletions examples/express/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { createYoga } from 'graphql-yoga'
import { createYoga, createSchema } from 'graphql-yoga'
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 +34,7 @@ export function buildApp(app: ReturnType<typeof express>) {
},
},
},
},
}),
logging: false,
})

Expand Down
4 changes: 2 additions & 2 deletions examples/express/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"target": "esnext",
"moduleResolution": "node",
"module": "commonjs",
"sourceMap": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"lib": ["esnext"]
"lib": ["esnext", "DOM"],
"skipLibCheck": true
}
}
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
Loading

0 comments on commit 9ca0def

Please sign in to comment.