graphql#ValueNode TypeScript Examples
The following examples show how to use
graphql#ValueNode.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: graphql.ts From amplify-codegen with Apache License 2.0 | 6 votes |
export function valueFromValueNode(valueNode: ValueNode): any | { kind: 'Variable'; variableName: string } {
switch (valueNode.kind) {
case 'IntValue':
case 'FloatValue':
return Number(valueNode.value);
case 'NullValue':
return null;
case 'ListValue':
return valueNode.values.map(valueFromValueNode);
case 'ObjectValue':
return valueNode.fields.reduce(
(object, field) => {
object[field.name.value] = valueFromValueNode(field.value);
return object;
},
{} as any
);
case 'Variable':
return { kind: 'Variable', variableName: valueNode.name.value };
default:
return valueNode.value;
}
}
Example #2
Source File: global-id.scalar.ts From nestjs-relay with MIT License | 6 votes |
parseLiteral(ast: ValueNode): ResolvedGlobalId {
if (ast.kind !== Kind.STRING) {
throw new GraphQLError(`Invalid ID type: ${ast.kind}`);
}
const { id, type } = fromGlobalId(ast.value);
if (!id || !type) {
throw new GraphQLError(`Invalid ID: ${ast.value}`);
}
return new ResolvedGlobalId({ type, id });
}
Example #3
Source File: hash.scalar.ts From nestjs-mercurius with MIT License | 5 votes |
parseLiteral(ast: ValueNode): string {
console.log('hash parseL');
if (ast.kind === Kind.STRING) {
return this.parseValue(ast.value);
}
return null;
}
Example #4
Source File: gqlTypes.ts From ra-data-prisma with MIT License | 5 votes |
argument = (name: NameNode, value: ValueNode): ArgumentNode => ({
kind: Kind.ARGUMENT,
name,
value,
})