Skip to content

Commit

Permalink
PR cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rebeccajfriedman committed Mar 6, 2019
1 parent f93a7d2 commit 83d8164
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/decode.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ function transformScalars(context, value) {
}

function recordTypeInformation(context, value) {
const selectionSet = context.selection.selectionSet;
const {typeBundle, typeSchema} = context.selection.selectionSet;

if (isValue(value)) {
if (value.__typename) {
value.type = schemaForType(selectionSet.typeBundle, value.__typename, selectionSet.typeSchema);
value.type = schemaForType(typeBundle, value.__typename, typeSchema);
} else {
value.type = selectionSet.typeSchema;
value.type = typeSchema;
}
}

Expand Down
20 changes: 10 additions & 10 deletions test/schema-type-test.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
import assert from 'assert';
import typeBundle from '../fixtures/custom-type-bundle';
import customTypeBundle from '../fixtures/custom-type-bundle';
import schemaForType from '../src/schema-for-type';
import Query from '../src/query';
import Mutation from '../src/mutation';
import realTypeBundle from '../fixtures/types'; // eslint-disable-line import/no-unresolved
import typeBundle from '../fixtures/types'; // eslint-disable-line import/no-unresolved

suite('schema-type-test', () => {
test('queries use the query type from the schema', () => {
let rootType = null;
const query = new Query(typeBundle, (root) => {
const query = new Query(customTypeBundle, (root) => {
rootType = root.typeSchema;
});

assert.deepEqual(schemaForType(typeBundle, 'CustomQueryRoot'), rootType);
assert.deepEqual(schemaForType(typeBundle, 'CustomQueryRoot'), query.typeSchema);
assert.deepEqual(schemaForType(customTypeBundle, 'CustomQueryRoot'), rootType);
assert.deepEqual(schemaForType(customTypeBundle, 'CustomQueryRoot'), query.typeSchema);
});

test('mutations use the mutation type from the schema', () => {
let rootType = null;
const mutation = new Mutation(typeBundle, (root) => {
const mutation = new Mutation(customTypeBundle, (root) => {
rootType = root.typeSchema;
});

assert.deepEqual(schemaForType(typeBundle, 'CustomMutation'), rootType);
assert.deepEqual(schemaForType(typeBundle, 'CustomMutation'), mutation.typeSchema);
assert.deepEqual(schemaForType(customTypeBundle, 'CustomMutation'), rootType);
assert.deepEqual(schemaForType(customTypeBundle, 'CustomMutation'), mutation.typeSchema);
});

test('returns the correct type for an enum', () => {
const currencyCodeType = realTypeBundle.types.CurrencyCode;
const currencyCodeType = typeBundle.types.CurrencyCode;

assert.deepEqual(schemaForType(realTypeBundle, 'CurrencyCode'), currencyCodeType);
assert.deepEqual(schemaForType(typeBundle, 'CurrencyCode'), currencyCodeType);
});
});

0 comments on commit 83d8164

Please sign in to comment.