-
Notifications
You must be signed in to change notification settings - Fork 7
Add assertions and type safety after #61 #69
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,8 @@ express or implied. See the License for the specific language governing | |
permissions and limitations under the License. | ||
*/ | ||
|
||
import { astFromValue, buildASTSchema, typeFromAST } from 'graphql'; | ||
import assert from 'node:assert'; | ||
import { astFromValue, buildASTSchema, isInputType, typeFromAST } from 'graphql'; | ||
import { gql } from 'graphql-tag'; // GraphQL library to parse the GraphQL query | ||
|
||
const useCallSubquery = false; | ||
|
@@ -27,12 +28,17 @@ const schema = buildASTSchema(schemaDataModel, { assumeValidSDL: true }); | |
export function resolveGraphDBQueryFromAppSyncEvent(event) { | ||
const fieldDef = getFieldDef(event.field); | ||
|
||
assert(fieldDef); | ||
|
||
const args = []; | ||
for (const inputDef of fieldDef.arguments) { | ||
for (const inputDef of fieldDef.arguments ?? []) { | ||
const value = event.arguments[inputDef.name.value]; | ||
|
||
if (value) { | ||
const inputType = typeFromAST(schema, inputDef.type); | ||
|
||
assert(isInputType(inputType)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For troubleshooting would be nice to add a value for the optional |
||
|
||
args.push({ | ||
kind: 'Argument', | ||
name: { kind: 'Name', value: inputDef.name.value }, | ||
|
@@ -99,8 +105,8 @@ function getTypeDefs(typeNameOrNames) { | |
function getFieldDef(fieldName) { | ||
const rootTypeDefs = getRootTypeDefs(); | ||
|
||
for (const rootDef of rootTypeDefs) { | ||
const fieldDef = rootDef.fields.find(def => def.name.value === fieldName); | ||
for (const rootTypeDef of rootTypeDefs) { | ||
const fieldDef = rootTypeDef.fields?.find(def => def.name.value === fieldName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps the |
||
|
||
if (fieldDef) { | ||
return fieldDef; | ||
|
@@ -1080,7 +1086,7 @@ function parseQueryInput(queryObjOrStr) { | |
* Accepts a GraphQL document or query string and outputs the graphDB query. | ||
* | ||
* @param {(Object|string)} queryObjOrStr the GraphQL document containing an operation to resolve | ||
* @returns {string} | ||
* @returns {Object} | ||
*/ | ||
export function resolveGraphDBQuery(queryObjOrStr) { | ||
let executeQuery = { query:'', parameters: {}, language: 'opencypher', refactorOutput: null }; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,5 @@ | |
"--create-update-aws-pipeline-neptune-endpoint", "<AIR_ROUTES_DB_HOST>:<AIR_ROUTES_DB_PORT>", | ||
"--output-resolver-query-https"], | ||
"host": "<AIR_ROUTES_DB_HOST>", | ||
"port": "<AIR_ROUTES_DB_PORT>", | ||
"testOutputFilesSize": ["output.resolver.graphql.js", "output.schema.graphql", "output.source.schema.graphql"], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you're cleaning up test files with unused fields can you also do the same for |
||
"testOutputFilesContent": ["output.schema.graphql", "output.source.schema.graphql"] | ||
"port": "<AIR_ROUTES_DB_PORT>" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For troubleshooting would be nice to add a value for the optional
message
parameter to indicate what expected state was not satisfied ie.Field definition for ${event.field} not found
.