Skip to content
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
16 changes: 13 additions & 3 deletions addon/fields/selections/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import createFieldInfo from '../info/create';
import { getFieldNameAndAlias } from '../name';
import { fragmentFieldsReducer, inlineFragmentFieldsReducer } from './fragments';
import { partial } from '../../utils';
import { partial, unwrapNonNull } from '../../utils';

const getFieldType = (type, fieldName) =>
fieldName !== '__typename' && type._fields[fieldName].type;
const getFieldType = (type, fieldName) => {
if (fieldName === '__typename') {
return null;
}

type = unwrapNonNull(type);

let field = type._fields[fieldName];
let fieldType = unwrapNonNull(field.type);

return fieldType;
}

export const selectedFieldsReducer =
(getFieldNameAndAlias, getFieldType, createFieldInfo, getType, type, fragments, selections, selection) => {
Expand Down
4 changes: 3 additions & 1 deletion addon/mocks/mutation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { contextSet, isFunction, reduceKeys } from '../utils';
import { contextSet, isFunction, reduceKeys, unwrapNonNull } from '../utils';
import { getRecords } from '../db';
import { resolveVarName } from '../filter/vars';

Expand All @@ -11,6 +11,8 @@ const mapVars = composeMapVars(resolveVarName);

export const composeMockMutation = (getRecords, mapVars) =>
(db, options = {}, _, vars, __, { fieldName, returnType }) => {
returnType = unwrapNonNull(returnType);

let { mutations = {}, varsMap = {} } = options;
let mutation = mutations[fieldName];
let records = getRecords(db, returnType.name);
Expand Down
4 changes: 4 additions & 0 deletions addon/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { GraphQLNonNull } from 'graphql';

const sortEdgesKeysBeforePageInfo = (list) => list.sort();

export function contextPush(context, k, v) {
Expand Down Expand Up @@ -35,3 +37,5 @@ export const composeReduceKeys = (sortKeys) =>
sortKeys(Object.keys(obj)).reduce(reducerFn, defaultValue);

export const reduceKeys = composeReduceKeys(sortEdgesKeysBeforePageInfo);

export const unwrapNonNull = (type) => type instanceof GraphQLNonNull ? type.ofType : type;
4 changes: 2 additions & 2 deletions tests/dummy/app/gql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type LineItem {
}

type LineItemConnection {
edges: [LineItemEdge]
edges: [LineItemEdge!]!
pageInfo: PageInfo!
}

Expand All @@ -29,7 +29,7 @@ type LineItemEdge {
}

type Mutation {
updatePerson(id: ID!, personAttributes: PersonAttributes!): Person
updatePerson(id: ID!, personAttributes: PersonAttributes!): Person!
}

interface Node {
Expand Down