Skip to content

Commit

Permalink
Show GraphQL Yoga and move docs to Apollo Server v3 (#2217)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkisiela committed Jun 20, 2022
1 parent 0781723 commit 9e5ec3a
Show file tree
Hide file tree
Showing 22 changed files with 534 additions and 695 deletions.
5 changes: 5 additions & 0 deletions .changeset/clean-rules-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'graphql-modules': patch
---

Add a deprecation note for createSchemaForApollo method
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"examples-basic",
"examples-di",
"examples-subscriptions",
"example-graphql-ez"
"graphql-yoga"
]
}
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Just take a look at the build status on Github Actions and find "Publish Canary"
More advanced usage at [graphql-modules.com](https://graphql-modules.com/docs)

```js
import { createModule, createApplication, gql } from 'graphql-modules';
import { createModule, createApplication, gql } from 'graphql-modules'

const module = createModule({
id: 'my-module',
Expand All @@ -59,12 +59,12 @@ const module = createModule({
posts: [Post]
}
`,
resolvers: blogResolvers,
});
resolvers: blogResolvers
})

const application = createApplication({
modules: [module],
});
modules: [module]
})
```

Inside the `examples` directory you can find the following examples:
Expand Down
24 changes: 0 additions & 24 deletions examples/ez/package.json

This file was deleted.

48 changes: 0 additions & 48 deletions examples/ez/src/app/auth/auth.module.ts

This file was deleted.

15 changes: 0 additions & 15 deletions examples/ez/src/app/social-network/social-network.module.ts

This file was deleted.

17 changes: 0 additions & 17 deletions examples/ez/src/app/user/user.module.ts

This file was deleted.

34 changes: 0 additions & 34 deletions examples/ez/src/index.ts

This file was deleted.

11 changes: 11 additions & 0 deletions examples/graphql-yoga/package.json
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"
}
}
6 changes: 6 additions & 0 deletions examples/graphql-yoga/src/app/index.ts
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],
});
51 changes: 51 additions & 0 deletions examples/graphql-yoga/src/app/post/post.module.ts
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);
},
},
},
});
20 changes: 20 additions & 0 deletions examples/graphql-yoga/src/app/post/post.provider.ts
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;
}
}
25 changes: 25 additions & 0 deletions examples/graphql-yoga/src/app/post/pubsub.ts
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();
},
};
}
4 changes: 4 additions & 0 deletions examples/graphql-yoga/src/app/post/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface Post {
author: string;
comment: string;
}
13 changes: 13 additions & 0 deletions examples/graphql-yoga/src/index.ts
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`);
});
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
"@babel/plugin-proposal-class-properties": "7.17.12",
"@changesets/apply-release-plan": "5.0.1",
"@changesets/cli": "2.23.0",
"@envelop/graphql-modules": "3.3.3",
"@graphql-tools/merge": "8.2.14",
"@graphql-yoga/node": "2.9.2",
"@types/benchmark": "2.1.1",
"@types/express": "4.17.13",
"@types/jest": "27.5.2",
Expand Down
Loading

0 comments on commit 9e5ec3a

Please sign in to comment.