Skip to content

Commit

Permalink
Add Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Federico committed Jun 18, 2021
1 parent 7c11094 commit 8e874d4
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/e2e/generated-definitions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,25 @@ describe('Generated Definitions', () => {
).toBe(await readFile(outputFile, 'utf8'));
});

it('should generate for a federated graph with typeDef', async () => {
const outputFile = generatedDefinitions('federation-typedef.test-definitions.ts');
const factory = new GraphQLDefinitionsFactory();
await factory.generate({
typePaths: [generatedDefinitions('federation-typedef.graphql')],
typeDefs: `enum Animal {
DOG
CAT
}`,
path: outputFile,
outputAs: 'class',
federation: true,
});

expect(
await readFile(generatedDefinitions('federation-typedef.fixture.ts'), 'utf8'),
).toBe(await readFile(outputFile, 'utf8'));
});

it('should generate with __typename field for each object type', async () => {
const typeDefs = await readFile(
generatedDefinitions('typename.graphql'),
Expand Down
33 changes: 33 additions & 0 deletions tests/generated-definitions/federation-typedef.fixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

/*
* ------------------------------------------------------
* THIS FILE WAS AUTOMATICALLY GENERATED (DO NOT MODIFY)
* -------------------------------------------------------
*/

/* tslint:disable */
/* eslint-disable */
export enum Animal {
DOG = "DOG",
CAT = "CAT"
}

export enum Category {
POST = "POST"
}

export class Post {
id: string;
title: string;
author: User;
category: Category;
}

export abstract class IQuery {
abstract getPosts(): Post[] | Promise<Post[]>;
}

export class User {
id: string;
posts?: Post[];
}
19 changes: 19 additions & 0 deletions tests/generated-definitions/federation-typedef.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
type Post {
id: ID!
title: String!
author: User!
category: Category!
}

extend type User @key(fields: "id") {
id: ID! @external
posts: [Post]
}

extend type Query {
getPosts: [Post]
}

extend enum Category {
POST
}

0 comments on commit 8e874d4

Please sign in to comment.