Skip to content
This repository was archived by the owner on Sep 3, 2021. It is now read-only.

Input object argument format for mutation API #531

Merged
merged 19 commits into from
Nov 6, 2020
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Update augmentSchemaTest.test.js
  • Loading branch information
michaeldgraham committed Oct 31, 2020
commit 3fd971ed9182819fe700af5b5c5e32e0705d51b2
60 changes: 1 addition & 59 deletions test/unit/augmentSchemaTest.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import test from 'ava';
import { parse, print, Kind } from 'graphql';
import { printSchemaDocument } from '../../src/augment/augment';
import { makeAugmentedSchema } from '../../src/index';
import { testSchema } from '../helpers/testSchema';
import { gql } from 'apollo-server';
import { compareSchema } from '../helpers/augmentSchemaTestHelpers';

test.cb('Test augmented schema', t => {
const parseTypeDefs = gql`
@@ -9161,60 +9160,3 @@ test.cb('Test augmented schema', t => {
});
t.end();
});

const compareSchema = ({ test, sourceSchema = {}, expectedSchema = {} }) => {
const expectedDefinitions = parse(expectedSchema, { noLocation: true })
.definitions;
const printedSourceSchema = printSchemaDocument({ schema: sourceSchema });
const augmentedDefinitions = parse(printedSourceSchema, { noLocation: true })
.definitions;
expectedDefinitions.forEach(expected => {
const matchingAugmented = findMatchingType({
definitions: augmentedDefinitions,
definition: expected
});
if (matchingAugmented) {
test.is(print(expected), print(matchingAugmented));
} else {
test.fail(
`\nAugmented schema is missing definition:\n${print(expected)}`
);
}
});
augmentedDefinitions.forEach(augmented => {
const matchingExpected = findMatchingType({
definitions: expectedDefinitions,
definition: augmented
});
if (matchingExpected) {
test.is(print(augmented), print(matchingExpected));
} else {
test.fail(
`\nExpected augmented schema is missing definition:\n${print(
augmented
)}`
);
}
});
};

const findMatchingType = ({ definitions = [], definition }) => {
const expectedKind = definition.kind;
const expectedName = definition.name;
return definitions.find(augmented => {
const augmentedName = augmented.name;
const matchesKind = augmented.kind == expectedKind;
let matchesName = false;
let isSchemaDefinition = false;
if (matchesKind) {
if (expectedName && augmentedName) {
if (expectedName.value === augmentedName.value) {
matchesName = true;
}
} else if (augmented.kind === Kind.SCHEMA_DEFINITION) {
isSchemaDefinition = true;
}
}
return matchesKind && (matchesName || isSchemaDefinition);
});
};