Skip to content

Commit 77afc73

Browse files
authored
Support for query fragments with Apollo (aws#103)
This changeset enables the use of graphQL query fragments with Apollo Server: -changed Apollo event handler to pass along any query fragments to the resolver -added logic to the resolver to detect referenced fragments in the query AST and replace them with the appropriate fragment's selection set -changed App Sync event handlers to throw an Error if a fragment is detected in the query so that the user is presented with an appropriate error message 'Fragments are not supported' instead of failing downstream and presenting a cryptic error message -changed functions in the resolver which require fragments data to accept a single object argument instead of multiple arguments for easier readability when calling the function -updated airports.customized.graphql test schema to have separate input types for create and update mutations so that the resolver unit test could verify test cases for mutations with fragments -note that this changeset does not address inline fragments
1 parent feb34d4 commit 77afc73

File tree

12 files changed

+486
-99
lines changed

12 files changed

+486
-99
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,5 @@ This release contains new support for Apollo Server integration.
5555
* Set limit on the expensive query which is retrieving distinct to and from labels for edges ([#89](https://github.com/aws/amazon-neptune-for-graphql/pull/89))
5656
* Added distinct input types for create and update mutations ([#93](https://github.com/aws/amazon-neptune-for-graphql/pull/93))
5757
* Enabled mutations for the Apollo Server ([#98](https://github.com/aws/amazon-neptune-for-graphql/pull/98))
58-
* Refactored integration tests to be less vulnerable to resolver logic changes ([#99](https://github.com/aws/amazon-neptune-for-graphql/pull/99))
58+
* Refactored integration tests to be less vulnerable to resolver logic changes ([#99](https://github.com/aws/amazon-neptune-for-graphql/pull/99))
59+
* Enabled usage of query fragments with Apollo Server ([#103](https://github.com/aws/amazon-neptune-for-graphql/pull/103))

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ When using custom scalars in your schema (specified via `--input-schema-file`),
311311
- Querying Neptune via SDK is not yet supported for Apollo Server, only HTTPS is supported.
312312
- Schemas specified by `--input-schema-file` with `--create-update-aws-pipeline` may not contain custom scalars. See [AWS App Sync Scalar types in GraphQL](https://docs.aws.amazon.com/appsync/latest/devguide/scalars.html) for more information.
313313
- Schemas specified by `--input-schema-file` with `--create-update-apollo-server` or `--create-update-apollo-server-subgraph` which contain custom scalars require manual steps to add custom scalar resolvers for additional query validation.
314+
- Query fragments are supported for Apollo Server but not yet for App Sync
315+
- Inline fragments are not yet supported
314316
<br>
315317

316318
# Roadmap

src/pipelineResources.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,11 @@ export function request(ctx) {
578578
}
579579
580580
export function response(ctx) {
581-
return ctx.result;
581+
const { error, result } = ctx;
582+
if (error) {
583+
util.appendError(error.message, error.type, result);
584+
}
585+
return result;
582586
}`
583587

584588
};

src/test/airports.customized.graphql

Lines changed: 81 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@ code: StringScalarFilters
1414
desc: StringScalarFilters
1515
}
1616

17+
input ContinentCreateInput {
18+
_id: ID @id
19+
type: String
20+
code: String
21+
desc: String
22+
}
23+
24+
input ContinentUpdateInput {
25+
_id: ID! @id
26+
type: String
27+
code: String
28+
desc: String
29+
}
30+
1731
type Country @alias(property:"country") {
1832
_id: ID! @id
1933
type: String
@@ -30,6 +44,20 @@ code: StringScalarFilters
3044
desc: StringScalarFilters
3145
}
3246

47+
input CountryCreateInput {
48+
_id: ID @id
49+
type: String
50+
code: String
51+
desc: String
52+
}
53+
54+
input CountryUpdateInput {
55+
_id: ID! @id
56+
type: String
57+
code: String
58+
desc: String
59+
}
60+
3361
type Version @alias(property:"version") {
3462
_id: ID! @id
3563
date: String
@@ -48,6 +76,24 @@ type: StringScalarFilters
4876
code: StringScalarFilters
4977
}
5078

79+
input VersionCreateInput {
80+
_id: ID @id
81+
date: String
82+
desc: String
83+
author: String
84+
type: String
85+
code: String
86+
}
87+
88+
input VersionUpdateInput {
89+
_id: ID! @id
90+
date: String
91+
desc: String
92+
author: String
93+
type: String
94+
code: String
95+
}
96+
5197
type Airport @alias(property:"airport") {
5298
_id: ID! @id
5399
type: String
@@ -87,6 +133,38 @@ region: StringScalarFilters
87133
elev: Int
88134
}
89135

136+
input AirportCreateInput {
137+
_id: ID @id
138+
type: String
139+
city: String
140+
icao: String
141+
code: String
142+
country: String
143+
lat: Float
144+
longest: Int
145+
runways: Int
146+
desc: String
147+
lon: Float
148+
region: String
149+
elev: Int
150+
}
151+
152+
input AirportUpdateInput {
153+
_id: ID! @id
154+
type: String
155+
city: String
156+
icao: String
157+
code: String
158+
country: String
159+
lat: Float
160+
longest: Int
161+
runways: Int
162+
desc: String
163+
lon: Float
164+
region: String
165+
elev: Int
166+
}
167+
90168
type Contains @alias(property:"contains") {
91169
_id: ID! @id
92170
}
@@ -130,12 +208,12 @@ getCountriesCount: Int @graphQuery(statement: "g.V().hasLabel('country').count()
130208
}
131209

132210
type Mutation {
133-
createNodeAirport(input: AirportInput!): Airport
134-
updateNodeAirport(input: AirportInput!): Airport
211+
createNodeAirport(input: AirportCreateInput!): Airport
212+
updateNodeAirport(input: AirportUpdateInput!): Airport
135213
connectNodeCountryToNodeAirportEdgeContains(from_id: ID!, to_id: ID!): Contains
136214
deleteEdgeContainsFromCountryToAirport(from_id: ID!, to_id: ID!): Boolean
137215
updateEdgeRouteFromAirportToAirport(from_id: ID!, to_id: ID!, edge: RouteInput!): Route
138-
createAirport(input: AirportInput!): Airport @graphQuery(statement: "CREATE (this:airport {$input}) RETURN this")
216+
createAirport(input: AirportCreateInput!): Airport @graphQuery(statement: "CREATE (this:airport {$input}) RETURN this")
139217
}
140218

141219
schema {

0 commit comments

Comments
 (0)