Skip to content

tests: Switch to using named args for graphql/graphqlSync #312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/__tests__/starWarsConnectionTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { expect } from 'chai';
import { describe, it } from 'mocha';
import { graphqlSync } from 'graphql';

import { StarWarsSchema } from './starWarsSchema';
import { StarWarsSchema as schema } from './starWarsSchema';

describe('Star Wars connections', () => {
it('fetches the first ship of the rebels', () => {
const query = `
const source = `
query RebelsShipsQuery {
rebels {
name,
Expand All @@ -21,7 +21,7 @@ describe('Star Wars connections', () => {
}
`;

expect(graphqlSync(StarWarsSchema, query)).to.deep.equal({
expect(graphqlSync({ schema, source })).to.deep.equal({
data: {
rebels: {
name: 'Alliance to Restore the Republic',
Expand All @@ -38,7 +38,7 @@ describe('Star Wars connections', () => {
});

it('fetches the first two ships of the rebels with a cursor', () => {
const query = `
const source = `
query MoreRebelShipsQuery {
rebels {
name,
Expand All @@ -54,7 +54,7 @@ describe('Star Wars connections', () => {
}
`;

expect(graphqlSync(StarWarsSchema, query)).to.deep.equal({
expect(graphqlSync({ schema, source })).to.deep.equal({
data: {
rebels: {
name: 'Alliance to Restore the Republic',
Expand All @@ -76,7 +76,7 @@ describe('Star Wars connections', () => {
});

it('fetches the next three ships of the rebels with a cursor', () => {
const query = `
const source = `
query EndOfRebelShipsQuery {
rebels {
name,
Expand All @@ -92,7 +92,7 @@ describe('Star Wars connections', () => {
}
`;

expect(graphqlSync(StarWarsSchema, query)).to.deep.equal({
expect(graphqlSync({ schema, source })).to.deep.equal({
data: {
rebels: {
name: 'Alliance to Restore the Republic',
Expand All @@ -118,7 +118,7 @@ describe('Star Wars connections', () => {
});

it('fetches no ships of the rebels at the end of connection', () => {
const query = `
const source = `
query RebelsQuery {
rebels {
name,
Expand All @@ -134,7 +134,7 @@ describe('Star Wars connections', () => {
}
`;

expect(graphqlSync(StarWarsSchema, query)).to.deep.equal({
expect(graphqlSync({ schema, source })).to.deep.equal({
data: {
rebels: {
name: 'Alliance to Restore the Republic',
Expand All @@ -147,7 +147,7 @@ describe('Star Wars connections', () => {
});

it('identifies the end of the list', () => {
const query = `
const source = `
query EndOfRebelShipsQuery {
rebels {
name,
Expand Down Expand Up @@ -175,7 +175,7 @@ describe('Star Wars connections', () => {
}
`;

expect(graphqlSync(StarWarsSchema, query)).to.deep.equal({
expect(graphqlSync({ schema, source })).to.deep.equal({
data: {
rebels: {
name: 'Alliance to Restore the Republic',
Expand Down
32 changes: 17 additions & 15 deletions src/__tests__/starWarsMutationTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { expect } from 'chai';
import { describe, it } from 'mocha';
import { graphqlSync } from 'graphql';

import { StarWarsSchema } from './starWarsSchema';
import { StarWarsSchema as schema } from './starWarsSchema';

describe('Star Wars mutations', () => {
it('mutates the data set', () => {
const mutation = `
const source = `
mutation AddBWingQuery($input: IntroduceShipInput!) {
introduceShip(input: $input) {
ship {
Expand All @@ -20,26 +20,28 @@ describe('Star Wars mutations', () => {
}
}
`;
const params = {
const variableValues = {
input: {
shipName: 'B-Wing',
factionId: '1',
clientMutationId: 'abcde',
},
};
const expected = {
introduceShip: {
ship: {
id: 'U2hpcDo5',
name: 'B-Wing',
},
faction: {
name: 'Alliance to Restore the Republic',

const result = graphqlSync({ schema, source, variableValues });
expect(result).to.deep.equal({
data: {
introduceShip: {
ship: {
id: 'U2hpcDo5',
name: 'B-Wing',
},
faction: {
name: 'Alliance to Restore the Republic',
},
clientMutationId: 'abcde',
},
clientMutationId: 'abcde',
},
};
const result = graphqlSync(StarWarsSchema, mutation, null, null, params);
expect(result).to.deep.equal({ data: expected });
});
});
});
37 changes: 14 additions & 23 deletions src/__tests__/starWarsObjectIdentificationTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { expect } from 'chai';
import { describe, it } from 'mocha';
import { graphqlSync } from 'graphql';

import { StarWarsSchema } from './starWarsSchema';
import { StarWarsSchema as schema } from './starWarsSchema';

describe('Star Wars object identification', () => {
it('fetches the ID and name of the rebels', () => {
const query = `
const source = `
query RebelsQuery {
rebels {
id
Expand All @@ -15,7 +15,7 @@ describe('Star Wars object identification', () => {
}
`;

expect(graphqlSync(StarWarsSchema, query)).to.deep.equal({
expect(graphqlSync({ schema, source })).to.deep.equal({
data: {
rebels: {
id: 'RmFjdGlvbjox',
Expand All @@ -26,7 +26,7 @@ describe('Star Wars object identification', () => {
});

it('refetches the rebels', () => {
const query = `
const source = `
query RebelsRefetchQuery {
node(id: "RmFjdGlvbjox") {
id
Expand All @@ -37,7 +37,7 @@ describe('Star Wars object identification', () => {
}
`;

expect(graphqlSync(StarWarsSchema, query)).to.deep.equal({
expect(graphqlSync({ schema, source })).to.deep.equal({
data: {
node: {
id: 'RmFjdGlvbjox',
Expand All @@ -48,7 +48,7 @@ describe('Star Wars object identification', () => {
});

it('fetches the ID and name of the empire', () => {
const query = `
const source = `
query EmpireQuery {
empire {
id
Expand All @@ -57,18 +57,15 @@ describe('Star Wars object identification', () => {
}
`;

expect(graphqlSync(StarWarsSchema, query)).to.deep.equal({
expect(graphqlSync({ schema, source })).to.deep.equal({
data: {
empire: {
id: 'RmFjdGlvbjoy',
name: 'Galactic Empire',
},
empire: { id: 'RmFjdGlvbjoy', name: 'Galactic Empire' },
},
});
});

it('refetches the empire', () => {
const query = `
const source = `
query EmpireRefetchQuery {
node(id: "RmFjdGlvbjoy") {
id
Expand All @@ -79,18 +76,15 @@ describe('Star Wars object identification', () => {
}
`;

expect(graphqlSync(StarWarsSchema, query)).to.deep.equal({
expect(graphqlSync({ schema, source })).to.deep.equal({
data: {
node: {
id: 'RmFjdGlvbjoy',
name: 'Galactic Empire',
},
node: { id: 'RmFjdGlvbjoy', name: 'Galactic Empire' },
},
});
});

it('refetches the X-Wing', () => {
const query = `
const source = `
query XWingRefetchQuery {
node(id: "U2hpcDox") {
id
Expand All @@ -101,12 +95,9 @@ describe('Star Wars object identification', () => {
}
`;

expect(graphqlSync(StarWarsSchema, query)).to.deep.equal({
expect(graphqlSync({ schema, source })).to.deep.equal({
data: {
node: {
id: 'U2hpcDox',
name: 'X-Wing',
},
node: { id: 'U2hpcDox', name: 'X-Wing' },
},
});
});
Expand Down
30 changes: 8 additions & 22 deletions src/connection/__tests__/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const schema = new GraphQLSchema({

describe('connectionDefinition()', () => {
it('includes connection and edge fields', () => {
const query = `
const source = `
query FriendsQuery {
user {
friends(first: 2) {
Expand All @@ -104,7 +104,7 @@ describe('connectionDefinition()', () => {
}
`;

expect(graphqlSync(schema, query)).to.deep.equal({
expect(graphqlSync({ schema, source })).to.deep.equal({
data: {
user: {
friends: {
Expand All @@ -126,7 +126,7 @@ describe('connectionDefinition()', () => {
});

it('works with forwardConnectionArgs', () => {
const query = `
const source = `
query FriendsQuery {
user {
friendsForward(first: 2) {
Expand All @@ -140,26 +140,19 @@ describe('connectionDefinition()', () => {
}
`;

expect(graphqlSync(schema, query)).to.deep.equal({
expect(graphqlSync({ schema, source })).to.deep.equal({
data: {
user: {
friendsForward: {
edges: [
{
node: { name: 'Nick' },
},
{
node: { name: 'Lee' },
},
],
edges: [{ node: { name: 'Nick' } }, { node: { name: 'Lee' } }],
},
},
},
});
});

it('works with backwardConnectionArgs', () => {
const query = `
const source = `
query FriendsQuery {
user {
friendsBackward(last: 2) {
Expand All @@ -173,18 +166,11 @@ describe('connectionDefinition()', () => {
}
`;

expect(graphqlSync(schema, query)).to.deep.equal({
expect(graphqlSync({ schema, source })).to.deep.equal({
data: {
user: {
friendsBackward: {
edges: [
{
node: { name: 'Joe' },
},
{
node: { name: 'Tim' },
},
],
edges: [{ node: { name: 'Joe' } }, { node: { name: 'Tim' } }],
},
},
},
Expand Down
Loading