graphql#InputValueDefinitionNode TypeScript Examples
The following examples show how to use
graphql#InputValueDefinitionNode.
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: generate-query.ts From graphql-query-generator with MIT License | 6 votes |
export function considerArgument(
arg: InputValueDefinitionNode,
config: InternalConfiguration
): boolean {
const isArgumentToIgnore = config.argumentsToIgnore.includes(arg.name.value)
const isArgumentToConsider = config.argumentsToConsider.includes(
arg.name.value
)
const isMand = isMandatoryType(arg.type)
const isOptional = !isMand
// Check for consistency
if (isMand && isArgumentToIgnore) {
throw new Error(`Cannot ignore non-null argument "${arg.name.value}"`)
}
if (isArgumentToIgnore && isArgumentToConsider) {
throw new Error(`Cannot ignore AND consider argument "${arg.name.value}"`)
}
// Return value based on options
if (isMand) {
return true
}
if (isArgumentToConsider) {
return true
}
if (isArgumentToIgnore) {
return false
}
if (isOptional && config.ignoreOptionalArguments) {
return false
}
return true
}
Example #2
Source File: generate-query.d.ts From graphql-query-generator with MIT License | 5 votes |
export declare function considerArgument(arg: InputValueDefinitionNode, config: InternalConfiguration): boolean;
Example #3
Source File: generate-query.ts From graphql-query-generator with MIT License | 5 votes |
/**
* Returns the first slicing argument defined in the field's @listSize
* directive, if:
* - The @listSize directive is indeed present, and defines slicing arguments
* - The requiredArguments do not already include any of the defined slicing
* arguments
* - The @listSize directive doesn't also set requireOneSlicingArgument to
* false
*
* TODO: add link to specification / documentation of @listSize directive
*/
function getMissingSlicingArg(
requiredArguments: InputValueDefinitionNode[],
field: FieldDefinitionNode,
schema: GraphQLSchema
): InputValueDefinitionNode {
// Return null if there is no @listSize directive:
const listSizeDirective = getListSizeDirective(field)
if (!listSizeDirective) return null
// Return null if @listSize directive defines no slicing arguments:
const slicingArgumentsArg = getSlicingArguments(listSizeDirective)
if (!slicingArgumentsArg) return null
// Return null if requireOneSlicingArgument is set to false:
const requireOneSlicingArg = getRequireOneSlicingArgument(listSizeDirective)
if (
requireOneSlicingArg &&
(requireOneSlicingArg.value as BooleanValueNode).value === false // already checked requireOneSlicingArg is a boolean
)
return null
// Return null if a slicing argument is already used:
const slicingArguments = (slicingArgumentsArg.value as ListValueNode).values // already checked slicingArgumentsArg is a list
.filter((value) => value.kind === 'StringValue')
.map((value) => (value as StringValueNode).value)
const usesSlicingArg = slicingArguments.some((slicingArg) =>
requiredArguments
.map((existing) => existing.name.value)
.includes(slicingArg)
)
if (usesSlicingArg) return null
// Returns the first slicing argument if slicing argument can be split on '.'
// then we just need to check the first level match
return field.arguments.find((arg) => {
return slicingArguments.find((slicingArgument) => {
const tokenizedPath = slicingArgument.split('.')
if (tokenizedPath.length < 1) return false
return arg.name.value === tokenizedPath[0]
})
})
}