Skip to content

Commit

Permalink
Add tests for new buildSchema options
Browse files Browse the repository at this point in the history
  • Loading branch information
trevor-scheer committed Jun 20, 2019
1 parent 38afc9d commit 56bf79e
Showing 1 changed file with 40 additions and 8 deletions.
48 changes: 40 additions & 8 deletions src/test/testMakeRemoteExecutableSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import {
subscriptionSchema,
subscriptionPubSubTrigger,
subscriptionPubSub,
makeSchemaRemoteFromLink,
makeSchemaRemoteFromLink
} from '../test/testingSchemas';
import { makeRemoteExecutableSchema } from '../stitching';

describe('remote subscriptions', () => {
let schema: GraphQLSchema;
Expand All @@ -19,8 +20,8 @@ describe('remote subscriptions', () => {
it('should work', done => {
const mockNotification = {
notifications: {
text: 'Hello world',
},
text: 'Hello world'
}
};

const subscription = parse(`
Expand All @@ -37,7 +38,7 @@ describe('remote subscriptions', () => {
expect(result).to.have.property('data');
expect(result.data).to.deep.equal(mockNotification);
!notificationCnt++ ? done() : null;
}),
})
);

subscriptionPubSub.publish(subscriptionPubSubTrigger, mockNotification);
Expand All @@ -46,8 +47,8 @@ describe('remote subscriptions', () => {
it('should work without triggering multiple times per notification', done => {
const mockNotification = {
notifications: {
text: 'Hello world',
},
text: 'Hello world'
}
};

const subscription = parse(`
Expand All @@ -64,14 +65,14 @@ describe('remote subscriptions', () => {
expect(result).to.have.property('data');
expect(result.data).to.deep.equal(mockNotification);
notificationCnt++;
}),
})
);

subscribe(schema, subscription).then(results =>
forAwaitEach(results as AsyncIterable<ExecutionResult>, (result: ExecutionResult) => {
expect(result).to.have.property('data');
expect(result.data).to.deep.equal(mockNotification);
}),
})
);

subscriptionPubSub.publish(subscriptionPubSubTrigger, mockNotification);
Expand All @@ -83,3 +84,34 @@ describe('remote subscriptions', () => {
}, 0);
});
});

describe('respects buildSchema options', () => {
const schema = `
type Query {
# Field description
custom: CustomScalar!
}
# Scalar description
scalar CustomScalar
`;

it('without comment descriptions', () => {
const remoteSchema = makeRemoteExecutableSchema({ schema });

const customScalar = remoteSchema.getType('CustomScalar');
expect(customScalar.description).to.eq(undefined);
});

it('with comment descriptions', () => {
const remoteSchema = makeRemoteExecutableSchema({
schema,
buildSchemaOptions: { commentDescriptions: true }
});

const field = remoteSchema.getQueryType().getFields()['custom'];
expect(field.description).to.eq('Field description');
const customScalar = remoteSchema.getType('CustomScalar');
expect(customScalar.description).to.eq('Scalar description');
});
});

0 comments on commit 56bf79e

Please sign in to comment.