node_modules.graphql.validation.rules.VariablesDefaultValueAllowed.mjs Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of apollo-client-maven-plugin Show documentation
Show all versions of apollo-client-maven-plugin Show documentation
Maven plugin for generating graphql clients
import { GraphQLError } from '../../error'; /**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* strict
*/
import { isNonNullType } from '../../type/definition';
export function defaultForRequiredVarMessage(varName, type, guessType) {
return 'Variable "$' + varName + '" of type "' + String(type) + '" is required and ' + 'will not use the default value. ' + ('Perhaps you meant to use type "' + String(guessType) + '".');
}
/**
* Variable's default value is allowed
*
* A GraphQL document is only valid if all variable default values are allowed
* due to a variable not being required.
*/
export function VariablesDefaultValueAllowed(context) {
return {
VariableDefinition: function VariableDefinition(node) {
var name = node.variable.name.value;
var defaultValue = node.defaultValue;
var type = context.getInputType();
if (isNonNullType(type) && defaultValue) {
context.reportError(new GraphQLError(defaultForRequiredVarMessage(name, type, type.ofType), [defaultValue]));
}
return false; // Do not traverse further.
},
SelectionSet: function SelectionSet() {
return false;
},
FragmentDefinition: function FragmentDefinition() {
return false;
}
};
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy