Skip to content

Commit

Permalink
Excluding keys that have trailing "edges.node" on them (#7273)
Browse files Browse the repository at this point in the history
* Excluding keys that have trailing "edges.node" on them as they will not be selectable anyway

* Updated CHANGELOG and added test case

* Forgot to change fit back to it
  • Loading branch information
cjbland authored Mar 18, 2021
1 parent 637326d commit 6313656
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ ___
- Randomize test suite (Diamond Lewis) [#7265](https://github.com/parse-community/parse-server/pull/7265)
- LDAP: Properly unbind client on group search error (Diamond Lewis) [#7265](https://github.com/parse-community/parse-server/pull/7265)
- Improve data consistency in Push and Job Status update (Diamond Lewis) [#7267](https://github.com/parse-community/parse-server/pull/7267)
- Excluding keys that have trailing edges.node when performing GraphQL resolver (Chris Bland) [#7273](https://github.com/parse-community/parse-server/pull/7273)
___
## 4.5.0
[Full Changelog](https://github.com/parse-community/parse-server/compare/4.4.0...4.5.0)
Expand Down
61 changes: 61 additions & 0 deletions spec/ParseGraphQLServer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5703,6 +5703,67 @@ describe('ParseGraphQLServer', () => {
result.data.parentClass.graphQLClasses.edges.map(edge => edge.node.objectId)
).toEqual([object3.id, object1.id, object2.id]);
});

it('should support including relation', async () => {
await prepareData();

await parseGraphQLServer.parseGraphQLSchema.schemaCache.clear();

const result1 = await apolloClient.query({
query: gql`
query FindRoles {
roles {
edges {
node {
name
}
}
}
}
`,
variables: {},
context: {
headers: {
'X-Parse-Session-Token': user1.getSessionToken(),
},
},
});

const result2 = await apolloClient.query({
query: gql`
query FindRoles {
roles {
edges {
node {
name
users {
edges {
node {
username
}
}
}
}
}
}
}
`,
variables: {},
context: {
headers: {
'X-Parse-Session-Token': user1.getSessionToken(),
},
},
});

expect(result1.data.roles.edges[0].node.name).toBeDefined();
expect(result1.data.roles.edges[0].node.users).toBeUndefined();
expect(result1.data.roles.edges[0].node.roles).toBeUndefined();
expect(result2.data.roles.edges[0].node.name).toBeDefined();
expect(result2.data.roles.edges[0].node.users).toBeDefined();
expect(result2.data.roles.edges[0].node.users.edges[0].node.username).toBeDefined();
expect(result2.data.roles.edges[0].node.roles).toBeUndefined();
});
});
});

Expand Down
1 change: 1 addition & 0 deletions src/GraphQL/loaders/parseClassQueries.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ const load = function (parseGraphQLSchema, parseClass, parseClassConfig: ?ParseG
selectedFields
.filter(field => field.startsWith('edges.node.'))
.map(field => field.replace('edges.node.', ''))
.filter(field => field.indexOf('edges.node') < 0)
);
const parseOrder = order && order.join(',');

Expand Down
1 change: 1 addition & 0 deletions src/GraphQL/loaders/parseClassTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ const load = (parseGraphQLSchema, parseClass, parseClassConfig: ?ParseGraphQLCla
selectedFields
.filter(field => field.startsWith('edges.node.'))
.map(field => field.replace('edges.node.', ''))
.filter(field => field.indexOf('edges.node') < 0)
);
const parseOrder = order && order.join(',');

Expand Down

0 comments on commit 6313656

Please sign in to comment.