Skip to content
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

Remove unnecessary async code #269

Merged
merged 1 commit into from
Jun 25, 2020
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
193 changes: 86 additions & 107 deletions src/__tests__/starWarsConnectionTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { StarWarsSchema } from './starWarsSchema.js';
import { graphql } from 'graphql';
import { graphqlSync } from 'graphql';

describe('Star Wars connections', () => {
it('fetches the first ship of the rebels', async () => {
it('fetches the first ship of the rebels', () => {
const query = `
query RebelsShipsQuery {
rebels {
Expand All @@ -21,25 +21,24 @@ describe('Star Wars connections', () => {
}
}
`;
const expected = {
rebels: {
name: 'Alliance to Restore the Republic',
ships: {
edges: [
{
node: {
name: 'X-Wing',

expect(graphqlSync(StarWarsSchema, query)).to.deep.equal({
data: {
rebels: {
name: 'Alliance to Restore the Republic',
ships: {
edges: [
{
node: { name: 'X-Wing' },
},
},
],
],
},
},
},
};
const result = await graphql(StarWarsSchema, query);
expect(result).to.deep.equal({ data: expected });
});
});

it('fetches the first two ships of the rebels with a cursor', async () => {
it('fetches the first two ships of the rebels with a cursor', () => {
const query = `
query MoreRebelShipsQuery {
rebels {
Expand All @@ -55,32 +54,29 @@ describe('Star Wars connections', () => {
}
}
`;
const expected = {
rebels: {
name: 'Alliance to Restore the Republic',
ships: {
edges: [
{
cursor: 'YXJyYXljb25uZWN0aW9uOjA=',
node: {
name: 'X-Wing',

expect(graphqlSync(StarWarsSchema, query)).to.deep.equal({
data: {
rebels: {
name: 'Alliance to Restore the Republic',
ships: {
edges: [
{
cursor: 'YXJyYXljb25uZWN0aW9uOjA=',
node: { name: 'X-Wing' },
},
},
{
cursor: 'YXJyYXljb25uZWN0aW9uOjE=',
node: {
name: 'Y-Wing',
{
cursor: 'YXJyYXljb25uZWN0aW9uOjE=',
node: { name: 'Y-Wing' },
},
},
],
],
},
},
},
};
const result = await graphql(StarWarsSchema, query);
expect(result).to.deep.equal({ data: expected });
});
});

it('fetches the next three ships of the rebels with a cursor', async () => {
it('fetches the next three ships of the rebels with a cursor', () => {
const query = `
query EndOfRebelShipsQuery {
rebels {
Expand All @@ -96,38 +92,33 @@ describe('Star Wars connections', () => {
}
}
`;
const expected = {
rebels: {
name: 'Alliance to Restore the Republic',
ships: {
edges: [
{
cursor: 'YXJyYXljb25uZWN0aW9uOjI=',
node: {
name: 'A-Wing',

expect(graphqlSync(StarWarsSchema, query)).to.deep.equal({
data: {
rebels: {
name: 'Alliance to Restore the Republic',
ships: {
edges: [
{
cursor: 'YXJyYXljb25uZWN0aW9uOjI=',
node: { name: 'A-Wing' },
},
},
{
cursor: 'YXJyYXljb25uZWN0aW9uOjM=',
node: {
name: 'Millenium Falcon',
{
cursor: 'YXJyYXljb25uZWN0aW9uOjM=',
node: { name: 'Millenium Falcon' },
},
},
{
cursor: 'YXJyYXljb25uZWN0aW9uOjQ=',
node: {
name: 'Home One',
{
cursor: 'YXJyYXljb25uZWN0aW9uOjQ=',
node: { name: 'Home One' },
},
},
],
],
},
},
},
};
const result = await graphql(StarWarsSchema, query);
expect(result).to.deep.equal({ data: expected });
});
});

it('fetches no ships of the rebels at the end of connection', async () => {
it('fetches no ships of the rebels at the end of connection', () => {
const query = `
query RebelsQuery {
rebels {
Expand All @@ -143,19 +134,20 @@ describe('Star Wars connections', () => {
}
}
`;
const expected = {
rebels: {
name: 'Alliance to Restore the Republic',
ships: {
edges: [],

expect(graphqlSync(StarWarsSchema, query)).to.deep.equal({
data: {
rebels: {
name: 'Alliance to Restore the Republic',
ships: {
edges: [],
},
},
},
};
const result = await graphql(StarWarsSchema, query);
expect(result).to.deep.equal({ data: expected });
});
});

it('identifies the end of the list', async () => {
it('identifies the end of the list', () => {
const query = `
query EndOfRebelShipsQuery {
rebels {
Expand Down Expand Up @@ -183,51 +175,38 @@ describe('Star Wars connections', () => {
}
}
`;
const expected = {
rebels: {
name: 'Alliance to Restore the Republic',
originalShips: {
edges: [
{
node: {
name: 'X-Wing',

expect(graphqlSync(StarWarsSchema, query)).to.deep.equal({
data: {
rebels: {
name: 'Alliance to Restore the Republic',
originalShips: {
edges: [
{
node: { name: 'X-Wing' },
},
},
{
node: {
name: 'Y-Wing',
{
node: { name: 'Y-Wing' },
},
},
],
pageInfo: {
hasNextPage: true,
],
pageInfo: { hasNextPage: true },
},
},
moreShips: {
edges: [
{
node: {
name: 'A-Wing',
moreShips: {
edges: [
{
node: { name: 'A-Wing' },
},
},
{
node: {
name: 'Millenium Falcon',
{
node: { name: 'Millenium Falcon' },
},
},
{
node: {
name: 'Home One',
{
node: { name: 'Home One' },
},
},
],
pageInfo: {
hasNextPage: false,
],
pageInfo: { hasNextPage: false },
},
},
},
};
const result = await graphql(StarWarsSchema, query);
expect(result).to.deep.equal({ data: expected });
});
});
});
6 changes: 3 additions & 3 deletions src/__tests__/starWarsMutationTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { StarWarsSchema } from './starWarsSchema.js';
import { graphql } from 'graphql';
import { graphqlSync } from 'graphql';

describe('Star Wars mutations', () => {
it('mutates the data set', async () => {
it('mutates the data set', () => {
const mutation = `
mutation AddBWingQuery($input: IntroduceShipInput!) {
introduceShip(input: $input) {
Expand Down Expand Up @@ -40,7 +40,7 @@ describe('Star Wars mutations', () => {
clientMutationId: 'abcde',
},
};
const result = await graphql(StarWarsSchema, mutation, null, null, params);
const result = graphqlSync(StarWarsSchema, mutation, null, null, params);
expect(result).to.deep.equal({ data: expected });
});
});
Loading