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
2 changes: 1 addition & 1 deletion src/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function resolverFactory(target, options) {
var ast = info.fieldASTs
, type = info.returnType
, list = options.list || type instanceof GraphQLList
, simpleAST = simplifyAST(ast[0], info)
, simpleAST = simplifyAST(ast, info)
, fields = simpleAST.fields
, findOptions = argsToFindOptions(args, model);

Expand Down
11 changes: 10 additions & 1 deletion src/simplifyAST.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,16 @@ module.exports = function simplifyAST(ast, info, parent) {
info = info || {};

if (ast.selectionSet) selections = ast.selectionSet.selections;
if (Array.isArray(ast)) selections = ast;
if (Array.isArray(ast)) {
let simpleAST = {};
ast.forEach(ast => {
simpleAST = deepMerge(
simpleAST, simplifyAST(ast, info)
);
});

return simpleAST;
}

if (isFragment(info, ast)) {
return simplifyAST(info.fragments[ast.name.value], info);
Expand Down
33 changes: 33 additions & 0 deletions test/integration/relay.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ describe('relay', function () {
name: {
type: GraphQLString,
resolve: () => 'Viewer!'
},
allProjects: {
type: new GraphQLList(projectType),
resolve: resolver(Project)
}
}),
interfaces: [nodeInterface]
Expand Down Expand Up @@ -346,6 +350,35 @@ describe('relay', function () {
});
});
});

it('should merge nested queries from multiple fragments', function() {
var globalId = toGlobalId('Viewer');
return graphql(schema, `
{
node(id: "${globalId}") {
id
... F0
... F1
}
}
fragment F0 on Viewer {
allProjects {
id
}
}
fragment F1 on Viewer {
allProjects {
id
name
}
}
`).then(result => {
if (result.errors) throw result.errors[0]

expect(result.data.node.allProjects[0].id).to.not.be.null;
expect(result.data.node.allProjects[0].name).to.not.be.null;
});
});
});

it('should support first queries on connections', function() {
Expand Down