-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show GraphQL Yoga and move docs to Apollo Server v3 (#2217)
- Loading branch information
1 parent
0781723
commit 9e5ec3a
Showing
22 changed files
with
534 additions
and
695 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'graphql-modules': patch | ||
--- | ||
|
||
Add a deprecation note for createSchemaForApollo method |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,6 @@ | |
"examples-basic", | ||
"examples-di", | ||
"examples-subscriptions", | ||
"example-graphql-ez" | ||
"graphql-yoga" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
examples/ez/src/app/social-network/social-network.module.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "graphql-yoga", | ||
"version": "0.0.0", | ||
"private": true, | ||
"main": "dist/index.js", | ||
"license": "MIT", | ||
"scripts": { | ||
"start": "ts-node --project ../../tsconfig.app.json ./src/index.ts", | ||
"build": "tsc" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { createApplication } from 'graphql-modules'; | ||
import { PostModule } from './post/post.module'; | ||
|
||
export const app = createApplication({ | ||
modules: [PostModule], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { createModule, gql } from 'graphql-modules'; | ||
import { PostsProvider } from './post.provider'; | ||
import { PubSub, PUB_SUB, providePubSub } from './pubsub'; | ||
|
||
export const PostModule = createModule({ | ||
id: 'post', | ||
dirname: __dirname, | ||
providers: [PostsProvider, providePubSub()], | ||
typeDefs: gql` | ||
type Subscription { | ||
postAdded: Post | ||
} | ||
type Query { | ||
posts: [Post] | ||
} | ||
type Mutation { | ||
addPost(author: String, comment: String): Post | ||
} | ||
type Post { | ||
author: String | ||
comment: String | ||
} | ||
`, | ||
resolvers: { | ||
Subscription: { | ||
postAdded: { | ||
// Additional event labels can be passed to asyncIterator creation | ||
subscribe( | ||
_root: any, | ||
_args: any, | ||
{ injector }: GraphQLModules.Context | ||
) { | ||
return injector.get<PubSub>(PUB_SUB).subscribe('POST_ADDED'); | ||
}, | ||
}, | ||
}, | ||
Query: { | ||
posts(_root: any, _args: any, { injector }: GraphQLModules.Context) { | ||
return injector.get(PostsProvider).getPosts(); | ||
}, | ||
}, | ||
Mutation: { | ||
addPost(_root: any, args: any, { injector }: GraphQLModules.Context) { | ||
return injector.get(PostsProvider).addPost(args); | ||
}, | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Injectable, Inject } from 'graphql-modules'; | ||
import { PUB_SUB, PubSub } from './pubsub'; | ||
import { Post } from './types'; | ||
|
||
@Injectable() | ||
export class PostsProvider { | ||
posts: Post[] = []; | ||
|
||
constructor(@Inject(PUB_SUB) private pubSub: PubSub) {} | ||
|
||
getPosts() { | ||
return this.posts; | ||
} | ||
|
||
addPost(post: Post) { | ||
this.posts.push(post); | ||
this.pubSub.publish('POST_ADDED', { postAdded: post }); | ||
return post; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { InjectionToken, FactoryProvider, Scope } from 'graphql-modules'; | ||
import { createPubSub, PubSub as TPubSub } from '@graphql-yoga/node'; | ||
import { Post } from './types'; | ||
|
||
type PubSub = TPubSub<{ | ||
POST_ADDED: [ | ||
{ | ||
postAdded: Post; | ||
} | ||
]; | ||
}>; | ||
|
||
export const PUB_SUB = new InjectionToken<PubSub>('PubSub'); | ||
|
||
export { PubSub }; | ||
|
||
export function providePubSub(): FactoryProvider<PubSub> { | ||
return { | ||
provide: PUB_SUB, | ||
scope: Scope.Singleton, | ||
useFactory() { | ||
return createPubSub(); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface Post { | ||
author: string; | ||
comment: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import 'reflect-metadata'; | ||
import { createServer } from '@graphql-yoga/node'; | ||
import { useGraphQLModules } from '@envelop/graphql-modules'; | ||
import { app } from './app'; | ||
|
||
const server = createServer({ | ||
plugins: [useGraphQLModules(app)], | ||
}); | ||
|
||
server.start().then(() => { | ||
// tslint:disable-next-line: no-console | ||
console.info(`🚀 Server ready at http://localhost:4000/graphql`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.