in templates/JSResolverOCHTTPS.js [55:108]
export function resolveGraphDBQueryFromEvent(event) {
const fieldDef = getFieldDef(event.field);
const args = [];
for (const inputDef of fieldDef.arguments ?? []) {
const value = event.arguments[inputDef.name.value];
if (value) {
const inputType = typeFromAST(schema, inputDef.type);
const astValue = astFromValue(value, inputType);
if (inputType instanceof GraphQLInputObjectType) {
// retrieve an ID field which may not necessarily be named 'id'
const idField = Object.values(inputType.getFields()).find(field => field.type.name === GraphQLID.name);
if (idField) {
// check if id was an input arg
const idValue = astValue.fields.find(f => f.name.value === idField.name);
if (idValue?.value?.kind === 'IntValue') {
// graphql astFromValue function can convert ID integer strings into integer type
// if input args contain an id and the graphql library has interpreted the value as an int, change it to treat the value as a string
idValue.value.kind = 'StringValue';
}
}
}
args.push({
kind: 'Argument',
name: { kind: 'Name', value: inputDef.name.value },
value: astValue
});
}
}
const fieldNode = {
kind: 'Field',
name: { kind: 'Name', value: event.field },
arguments: args,
selectionSet: event.selectionSet
};
const obj = {
kind: 'Document',
definitions: [
{
kind: 'OperationDefinition',
operation: 'query',
selectionSet: {
kind: 'SelectionSet',
selections: [fieldNode]
}
}
]
};
const graphQuery = resolveGraphDBQuery(obj);
return graphQuery;
}