graphql/utilities/validation

Functions

assertValidName()

Deprecated in v16

Upholds the spec rules about naming. This helper is retained for backwards compatibility; call assertName instead because assertValidName will be removed in v17.

Signature:

assertValidName(name: string): string

Arguments

NameTypeDescription
namestringThe GraphQL name to validate.

Returns

TypeDescription
stringThe validated GraphQL name.

Example

import { assertValidName } from 'graphql/utilities';
 
const name = assertValidName('User');
 
// name: 'User'

isValidNameError()

Deprecated in v16

Returns an Error if a name is invalid. This helper is retained for backwards compatibility; call assertName and catch the thrown GraphQLError instead because isValidNameError will be removed in v17.

Signature:

isValidNameError(name: string): GraphQLError | undefined

Arguments

NameTypeDescription
namestringThe GraphQL name to validate.

Returns

TypeDescription
GraphQLError | undefinedA GraphQLError if the name is invalid; otherwise undefined.

Example

import { isValidNameError } from 'graphql/utilities';
 
const error = isValidNameError('User');
 
// error: undefined