-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:thiagomini/nest-graphql into test…
…/function-utils
- Loading branch information
Showing
114 changed files
with
6,184 additions
and
3,104 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
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 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 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 |
---|---|---|
@@ -1,2 +1,5 @@ | ||
packages/**/tests/generated-definitions/*.ts | ||
packages/**/tests/**/*.fixture.ts | ||
packages/**/tests/**/*.fixture.ts | ||
|
||
packages/**/tests/cases/**/*.ts | ||
packages/**/tests/cases/**/*.ts |
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 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 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 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 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
22 changes: 22 additions & 0 deletions
22
packages/apollo/tests/code-first-graphql-federation2/gateway/gateway.module.ts
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,22 @@ | ||
import { IntrospectAndCompose } from '@apollo/gateway-v2'; | ||
import { Module } from '@nestjs/common'; | ||
import { GraphQLModule } from '@nestjs/graphql'; | ||
import { ApolloGatewayDriver, ApolloGatewayDriverConfig } from '../../../lib'; | ||
|
||
@Module({ | ||
imports: [ | ||
GraphQLModule.forRoot<ApolloGatewayDriverConfig>({ | ||
driver: ApolloGatewayDriver, | ||
gateway: { | ||
debug: false, | ||
supergraphSdl: new IntrospectAndCompose({ | ||
subgraphs: [ | ||
{ name: 'users', url: 'http://localhost:3001/graphql' }, | ||
{ name: 'posts', url: 'http://localhost:3002/graphql' }, | ||
], | ||
}), | ||
}, | ||
}), | ||
], | ||
}) | ||
export class AppModule {} |
24 changes: 24 additions & 0 deletions
24
...ages/apollo/tests/code-first-graphql-federation2/posts-service/federation-posts.module.ts
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,24 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { GraphQLModule } from '@nestjs/graphql'; | ||
import { ApolloServerPluginInlineTraceDisabled } from 'apollo-server-core'; | ||
import { ApolloDriverConfig } from '../../../lib'; | ||
import { ApolloFederationDriver } from '../../../lib/drivers'; | ||
import { PostsModule } from './posts/posts.module'; | ||
import { User } from './posts/user.entity'; | ||
|
||
@Module({ | ||
imports: [ | ||
GraphQLModule.forRoot<ApolloDriverConfig>({ | ||
driver: ApolloFederationDriver, | ||
autoSchemaFile: { | ||
federation: 2, | ||
}, | ||
buildSchemaOptions: { | ||
orphanedTypes: [User], | ||
}, | ||
plugins: [ApolloServerPluginInlineTraceDisabled()], | ||
}), | ||
PostsModule, | ||
], | ||
}) | ||
export class AppModule {} |
10 changes: 10 additions & 0 deletions
10
packages/apollo/tests/code-first-graphql-federation2/posts-service/posts/post-type.enum.ts
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,10 @@ | ||
import { registerEnumType } from '@nestjs/graphql'; | ||
|
||
export enum PostType { | ||
IMAGE = 'IMAGE', | ||
TEXT = 'TEXT', | ||
} | ||
|
||
registerEnumType(PostType, { | ||
name: 'PostType', | ||
}); |
23 changes: 23 additions & 0 deletions
23
packages/apollo/tests/code-first-graphql-federation2/posts-service/posts/posts.entity.ts
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,23 @@ | ||
import { Directive, Field, ID, ObjectType } from '@nestjs/graphql'; | ||
import { PostType } from './post-type.enum'; | ||
|
||
@ObjectType() | ||
@Directive('@key(fields: "id")') | ||
export class Post { | ||
@Field(() => ID) | ||
id: string; | ||
|
||
@Field() | ||
title: string; | ||
|
||
@Field() | ||
body: string; | ||
|
||
userId: string; | ||
|
||
@Field({ nullable: true }) | ||
publishDate: Date; | ||
|
||
@Field(() => PostType, { nullable: true }) | ||
type: PostType; | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/apollo/tests/code-first-graphql-federation2/posts-service/posts/posts.module.ts
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,9 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { PostsResolvers } from './posts.resolvers'; | ||
import { UsersResolvers } from './users.resolvers'; | ||
import { PostsService } from './posts.service'; | ||
|
||
@Module({ | ||
providers: [PostsResolvers, PostsService, UsersResolvers], | ||
}) | ||
export class PostsModule {} |
42 changes: 42 additions & 0 deletions
42
packages/apollo/tests/code-first-graphql-federation2/posts-service/posts/posts.resolvers.ts
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,42 @@ | ||
import { | ||
Args, | ||
ID, | ||
Mutation, | ||
Parent, | ||
Query, | ||
ResolveField, | ||
Resolver, | ||
} from '@nestjs/graphql'; | ||
import { PostType } from './post-type.enum'; | ||
import { Post } from './posts.entity'; | ||
import { PostsService } from './posts.service'; | ||
import { User } from './user.entity'; | ||
|
||
@Resolver(Post) | ||
export class PostsResolvers { | ||
constructor(private readonly postsService: PostsService) {} | ||
|
||
@Query(() => [Post]) | ||
getPosts( | ||
@Args('type', { nullable: true, type: () => PostType }) type: PostType, | ||
) { | ||
if (type) { | ||
return this.postsService.findByType(type); | ||
} else { | ||
return this.postsService.findAll(); | ||
} | ||
} | ||
|
||
@Mutation(() => Post) | ||
publishPost( | ||
@Args('id', { type: () => ID }) id, | ||
@Args('publishDate') publishDate: Date, | ||
) { | ||
return this.postsService.publish(id, publishDate); | ||
} | ||
|
||
@ResolveField('user', () => User, { nullable: true }) | ||
getUser(@Parent() post: Post) { | ||
return { __typename: 'User', id: post.userId }; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
packages/apollo/tests/code-first-graphql-federation2/posts-service/posts/posts.service.ts
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,39 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { Post } from './posts.entity'; | ||
import { PostType } from './post-type.enum'; | ||
|
||
@Injectable() | ||
export class PostsService { | ||
private readonly posts: Post[] = [ | ||
{ | ||
id: '1', | ||
title: 'HELLO WORLD', | ||
body: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', | ||
userId: '5', | ||
publishDate: new Date(0), | ||
type: PostType.TEXT, | ||
}, | ||
]; | ||
|
||
findAll() { | ||
return Promise.resolve(this.posts); | ||
} | ||
|
||
findById(id: string) { | ||
return Promise.resolve(this.posts.find((p) => p.id === id)); | ||
} | ||
|
||
findByUserId(id: string) { | ||
return Promise.resolve(this.posts.filter((p) => p.userId === id)); | ||
} | ||
|
||
findByType(type: PostType) { | ||
return Promise.resolve(this.posts.filter((p) => p.type === type)); | ||
} | ||
|
||
async publish(id: string, publishDate: Date) { | ||
const post = await this.findById(id); | ||
post.publishDate = publishDate; | ||
return post; | ||
} | ||
} |
Oops, something went wrong.