Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/union member projection #312

Merged
merged 41 commits into from
Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
c8e1afe
Missing copyright headers
darrellwarde Jun 15, 2021
900bb4b
Point to prerelease documentation for 2.0.0 branch
darrellwarde Jun 15, 2021
20ff60f
General housekeeping before release
darrellwarde Jun 15, 2021
fb03f39
Update code comment
darrellwarde Jun 15, 2021
ec5883a
Merge remote-tracking branch 'upstream/2.0.0' into 2.0.0
darrellwarde Jun 15, 2021
9020391
Merge branch 'master' into 2.0.0
darrellwarde Jun 16, 2021
2568902
Fix TCK tests broken from merge
darrellwarde Jun 16, 2021
5965c75
fix(jwt): req.cookies might be undefined
gasp Jun 16, 2021
b479c85
Add scalars earlier in schema augmentation for use in types and inter…
darrellwarde Jun 18, 2021
dd96ac9
Merge remote-tracking branch 'upstream/2.0.0' into 2.0.0
darrellwarde Jun 18, 2021
90b388f
Merge branch 'master' into 2.0.0
darrellwarde Jun 18, 2021
ebc95e8
Changes to accomodate merge from master
darrellwarde Jun 18, 2021
af33c5e
Merge pull request #267 from gasp/fix/jwt-cookie-optional-chaining
oskarhane Jun 22, 2021
6d1853d
fix: use package json for useragent name and version (#271)
danstarns Jun 22, 2021
689c778
config: remove codeowners (#277)
danstarns Jun 22, 2021
283b179
Version update
Jun 22, 2021
1972059
Merge branch 'release/06-22-2021'
Jun 22, 2021
00871c8
fix(login): avoid confusion caused by secondary button (#265)
gasp Jun 28, 2021
502bd00
Merge branch '2.0.0' of github.com:neo4j/graphql into 2.0.0
darrellwarde Jun 29, 2021
2b1f1b3
Merge branch '2.0.0' of github.com:darrellwarde/graphql into 2.0.0
darrellwarde Jun 29, 2021
ba9ee02
fix: losing params while creating Auth Predicate (#281)
mathix420 Jun 30, 2021
6fdaeda
feat: add projection to top level cypher directive (#251)
danstarns Jun 30, 2021
5261188
Merge remote-tracking branch 'upstream/2.0.0' into 2.0.0
darrellwarde Jul 1, 2021
559cd18
Merge remote-tracking branch 'upstream/2.0.0' into 2.0.0
darrellwarde Jul 2, 2021
0107313
Merge remote-tracking branch 'upstream/2.0.0' into 2.0.0
darrellwarde Jul 5, 2021
5e51f67
Merge remote-tracking branch 'upstream/2.0.0' into 2.0.0
darrellwarde Jul 5, 2021
7e531cf
Merge remote-tracking branch 'upstream/2.0.0' into 2.0.0
darrellwarde Jul 5, 2021
662acc3
Fix for loss of scalar and field level resolvers (#297)
darrellwarde Jul 6, 2021
e55bd53
Mention double escaping for @cypher directive
darrellwarde Jul 6, 2021
1d5351d
Merge pull request #299 from darrellwarde/docs/cypher-escaping
darrellwarde Jul 6, 2021
46f64c6
Version update
Jul 6, 2021
01a7c06
Merge branch 'release/1.1.0'
Jul 6, 2021
dea402b
Merge branch 'master' into 2.0.0
darrellwarde Jul 8, 2021
4971e65
Merge remote-tracking branch 'upstream/2.0.0' into 2.0.0
darrellwarde Jul 8, 2021
5e928f6
Allows users to pass in decoded JWT (#303)
darrellwarde Jul 9, 2021
decaf85
Version update
Jul 12, 2021
e0220be
Merge branch 'release/07-12-2021'
Jul 12, 2021
7cbe049
Merge remote-tracking branch 'upstream/2.0.0' into 2.0.0
darrellwarde Jul 12, 2021
6db4f39
Merge branch 'master' into 2.0.0
darrellwarde Jul 12, 2021
43a5d63
Merge remote-tracking branch 'upstream/2.0.0' into 2.0.0
darrellwarde Jul 12, 2021
2bd5cd0
Selectively project union members
darrellwarde Jul 12, 2021
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
13 changes: 11 additions & 2 deletions packages/graphql/src/translate/create-projection-and-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,19 @@ function createProjectionAndParams({
const isArray = relationField.typeMeta.array;

if (relationField.union) {
const referenceNodes = context.neoSchema.nodes.filter((x) =>
relationField.union?.nodes?.includes(x.name)
let referenceNodes = context.neoSchema.nodes.filter(
(x) =>
relationField.union?.nodes?.includes(x.name) &&
Object.prototype.hasOwnProperty.call(fieldFields, x.name)
);

// If for example, just selecting __typename, error will be thrown without this
if (!referenceNodes.length) {
referenceNodes = context.neoSchema.nodes.filter((x) =>
relationField.union?.nodes?.includes(x.name)
);
}

const unionStrs: string[] = [
`${key}: ${!isArray ? "head(" : ""} [(${
chainStr || varName
Expand Down
72 changes: 30 additions & 42 deletions packages/graphql/tests/integration/nested-unions.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,27 +117,21 @@ describe("Nested unions", () => {
contextValue: { driver },
});
expect(gqlResult.errors).toBeFalsy();
// expect(gqlResult.data?.updateMovies.movies).toEqual([
// {
// title: movieTitle,
// actors: [
// {
// name: actorName,
// actedIn: [
// {},
// {
// name: seriesName,
// },
// ],
// },
// ],
// },
// ]);
expect(gqlResult.data?.updateMovies.movies[0].title).toEqual(movieTitle);
expect(gqlResult.data?.updateMovies.movies[0].actors[0].name).toEqual(actorName);
expect(gqlResult.data?.updateMovies.movies[0].actors[0].actedIn).toContainEqual({
name: seriesName,
});
expect(gqlResult.data?.updateMovies.movies).toEqual([
{
title: movieTitle,
actors: [
{
name: actorName,
actedIn: [
{
name: seriesName,
},
],
},
],
},
]);
} finally {
await session.close();
}
Expand Down Expand Up @@ -383,27 +377,21 @@ describe("Nested unions", () => {
contextValue: { driver },
});
expect(gqlResult.errors).toBeFalsy();
// expect(gqlResult.data?.updateMovies.movies).toEqual([
// {
// title: movieTitle,
// actors: [
// {
// name: actorName,
// actedIn: [
// {},
// {
// name: seriesName,
// },
// ],
// },
// ],
// },
// ]);
expect(gqlResult.data?.updateMovies.movies[0].title).toEqual(movieTitle);
expect(gqlResult.data?.updateMovies.movies[0].actors[0].name).toEqual(actorName);
expect(gqlResult.data?.updateMovies.movies[0].actors[0].actedIn).toContainEqual({
name: seriesName,
});
expect(gqlResult.data?.updateMovies.movies).toEqual([
{
title: movieTitle,
actors: [
{
name: actorName,
actedIn: [
{
name: seriesName,
},
],
},
],
},
]);

const cypherMovie = `
MATCH (m:Movie {title: $movieTitle})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ WITH this, this_connect_actors_LeadActor0_node
OPTIONAL MATCH (this_connect_actors_LeadActor0_node_actedIn_Series0_node:Series)
WHERE this_connect_actors_LeadActor0_node_actedIn_Series0_node.name = $this_connect_actors_LeadActor0_node_actedIn_Series0_node_name
FOREACH(_ IN CASE this_connect_actors_LeadActor0_node_actedIn_Series0_node WHEN NULL THEN [] ELSE [1] END | MERGE (this_connect_actors_LeadActor0_node)-[:ACTED_IN]->(this_connect_actors_LeadActor0_node_actedIn_Series0_node) )
RETURN this { .title, actors: [(this)<-[:ACTED_IN]-(this_actors) WHERE "LeadActor" IN labels(this_actors) OR "Extra" IN labels(this_actors) | head( [ this_actors IN [this_actors] WHERE "LeadActor" IN labels (this_actors) | this_actors { __resolveType: "LeadActor", .name, actedIn: [(this_actors)-[:ACTED_IN]->(this_actors_actedIn) WHERE "Movie" IN labels(this_actors_actedIn) OR "Series" IN labels(this_actors_actedIn) | head( [ this_actors_actedIn IN [this_actors_actedIn] WHERE "Movie" IN labels (this_actors_actedIn) | this_actors_actedIn { __resolveType: "Movie" } ] + [ this_actors_actedIn IN [this_actors_actedIn] WHERE "Series" IN labels (this_actors_actedIn) | this_actors_actedIn { __resolveType: "Series", .name } ] ) ] } ] + [ this_actors IN [this_actors] WHERE "Extra" IN labels (this_actors) | this_actors { __resolveType: "Extra" } ] ) ] } AS this
RETURN this { .title, actors: [(this)<-[:ACTED_IN]-(this_actors) WHERE "LeadActor" IN labels(this_actors) | head( [ this_actors IN [this_actors] WHERE "LeadActor" IN labels (this_actors) | this_actors { __resolveType: "LeadActor", .name, actedIn: [(this_actors)-[:ACTED_IN]->(this_actors_actedIn) WHERE "Series" IN labels(this_actors_actedIn) | head( [ this_actors_actedIn IN [this_actors_actedIn] WHERE "Series" IN labels (this_actors_actedIn) | this_actors_actedIn { __resolveType: "Series", .name } ] ) ] } ] ) ] } AS this
```

**Expected Cypher params**
Expand Down Expand Up @@ -148,7 +148,7 @@ WITH this, this_disconnect_actors_LeadActor0
OPTIONAL MATCH (this_disconnect_actors_LeadActor0)-[this_disconnect_actors_LeadActor0_actedIn_Series0_rel:ACTED_IN]->(this_disconnect_actors_LeadActor0_actedIn_Series0:Series)
WHERE this_disconnect_actors_LeadActor0_actedIn_Series0.name = $updateMovies.args.disconnect.actors.LeadActor[0].disconnect.actedIn.Series[0].where.node.name
FOREACH(_ IN CASE this_disconnect_actors_LeadActor0_actedIn_Series0 WHEN NULL THEN [] ELSE [1] END | DELETE this_disconnect_actors_LeadActor0_actedIn_Series0_rel )
RETURN this { .title, actors: [(this)<-[:ACTED_IN]-(this_actors) WHERE "LeadActor" IN labels(this_actors) OR "Extra" IN labels(this_actors) | head( [ this_actors IN [this_actors] WHERE "LeadActor" IN labels (this_actors) | this_actors { __resolveType: "LeadActor", .name, actedIn: [(this_actors)-[:ACTED_IN]->(this_actors_actedIn) WHERE "Movie" IN labels(this_actors_actedIn) OR "Series" IN labels(this_actors_actedIn) | head( [ this_actors_actedIn IN [this_actors_actedIn] WHERE "Movie" IN labels (this_actors_actedIn) | this_actors_actedIn { __resolveType: "Movie" } ] + [ this_actors_actedIn IN [this_actors_actedIn] WHERE "Series" IN labels (this_actors_actedIn) | this_actors_actedIn { __resolveType: "Series", .name } ] ) ] } ] + [ this_actors IN [this_actors] WHERE "Extra" IN labels (this_actors) | this_actors { __resolveType: "Extra" } ] ) ] } AS this
RETURN this { .title, actors: [(this)<-[:ACTED_IN]-(this_actors) WHERE "LeadActor" IN labels(this_actors) | head( [ this_actors IN [this_actors] WHERE "LeadActor" IN labels (this_actors) | this_actors { __resolveType: "LeadActor", .name, actedIn: [(this_actors)-[:ACTED_IN]->(this_actors_actedIn) WHERE "Series" IN labels(this_actors_actedIn) | head( [ this_actors_actedIn IN [this_actors_actedIn] WHERE "Series" IN labels (this_actors_actedIn) | this_actors_actedIn { __resolveType: "Series", .name } ] ) ] } ] ) ] } AS this
```

**Expected Cypher params**
Expand Down