Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eddeee888 committed Jan 18, 2025
1 parent 6ee50e4 commit 9efc60b
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions packages/graphql-codegen-cli/tests/config.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { createContext, ensureContext } from '../src/index.js';

describe('Codegen config - Context', () => {
it('loads and merge multiple schemas when using GraphQL config', async () => {
const context = await createContext({
config: './packages/graphql-codegen-cli/tests/test-files/graphql.config.js',
project: 'prj1',
errorsOnly: true,
overwrite: true,
profile: true,
require: [],
silent: false,
watch: false,
});

const schema1 = /* GraphQL */ `
type Query
scalar Date
`;

const schema2 = /* GraphQL */ `
extend type Query {
me: User
}
type User {
id: ID!
name: String!
createdAt: Date!
}
`;

const schema3 = /* GraphQL */ `
extend type Query {
media: Media
}
interface Media {
id: ID!
}
type Image implements Media {
id: ID!
url: String!
}
type Book implements Media {
id: ID!
title: String!
}
`;

const mergedSchema = await context.loadSchema([schema1, schema2, schema3]);

const typeMap = mergedSchema.getTypeMap();

expect(typeMap['Query']).toBeDefined();
expect(typeMap['Date']).toBeDefined();
expect(typeMap['User']).toBeDefined();
expect(typeMap['Media']).toBeDefined();
expect(typeMap['Image']).toBeDefined();
expect(typeMap['Book']).toBeDefined();
});

it('loads and merge multiple schemas when using input config', async () => {
const context = ensureContext({
generates: {},
});

const schema1 = /* GraphQL */ `
type Mutation
scalar DateTime
`;

const schema2 = /* GraphQL */ `
extend type Mutation {
createUser: User
}
type User {
id: ID!
createdAt: DateTime!
}
`;

const mergedSchema = await context.loadSchema([schema1, schema2]);

const typeMap = mergedSchema.getTypeMap();

expect(typeMap['Mutation']).toBeDefined();
expect(typeMap['DateTime']).toBeDefined();
expect(typeMap['User']).toBeDefined();
});
});

0 comments on commit 9efc60b

Please sign in to comment.