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
6 changes: 5 additions & 1 deletion src/simplifyAST.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ module.exports = function simplifyAST(ast, info, parent) {
}

simpleAST.fields[key].args = selection.arguments.reduce(function (args, arg) {
args[arg.name.value] = arg.value.value;
if (arg.value.values) {
args[arg.name.value] = arg.value.values.map(value => value.value);
} else {
args[arg.name.value] = arg.value.value;
}
return args;
}, {});

Expand Down
33 changes: 33 additions & 0 deletions test/integration/resolver.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,21 @@ describe('resolver', function () {
}
}

return options;
}
})
},
tasksByIds: {
type: new GraphQLList(taskType),
args: {
ids: {
type: new GraphQLList(GraphQLInt)
}
},
resolve: resolver(User.Tasks, {
before: (options, args) => {
options.where = options.where || {};
options.where.id = { $in: args.ids };
return options;
}
})
Expand Down Expand Up @@ -1091,6 +1106,24 @@ describe('resolver', function () {
});
});

it('should resolve args from array to before', function () {
var user = this.userB;

return graphql(schema, `
{
user(id: ${user.get('id')}) {
tasksByIds(ids: [${user.tasks[0].get('id')}]) {
id
}
}
}
`).then(function (result) {
if (result.errors) throw new Error(result.errors[0].stack);

expect(result.data.user.tasksByIds.length).to.equal(1);
});
});

describe('filterAttributes', function () {
beforeEach(function () {
this.defaultValue = resolver.filterAttributes;
Expand Down
28 changes: 27 additions & 1 deletion test/unit/simplifyAST.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,32 @@ describe('simplifyAST', function () {
});
});

it('should simplify a basic structure with array args', function () {
expect(simplifyAST(parse(`
{
luke: human(id: ["1000", "1003"]) {
name
}
}
`))).to.deep.equal({
args: {},
fields: {
luke: {
key: "human",
args: {
id: ["1000", "1003"]
},
fields: {
name: {
args: {},
fields: {}
}
}
}
}
})
});

it('should simplify a basic structure with an inline fragment', function () {
expect(simplifyAST(parse(`
{
Expand Down Expand Up @@ -258,4 +284,4 @@ describe('simplifyAST', function () {
}
})
});
});
});