Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function validateQuery(
ast: DocumentNode,
schema: GraphQLSchema | null | undefined = null,
customRules?: Array,
isRelayCompatMode?: boolean,
): Array {
// We cannot validate the query unless a schema is provided.
if (!schema) {
return [];
}
const validationErrorAnnotations = mapCat(
validateWithCustomRules(schema, ast, customRules, isRelayCompatMode),
error => annotations(error, SEVERITY.ERROR, 'Validation'),
);
// Note: findDeprecatedUsages was added in graphql@0.9.0, but we want to
// support older versions of graphql-js.
const deprecationWarningAnnotations = !findDeprecatedUsages
? []
: mapCat(findDeprecatedUsages(schema, ast), error =>
annotations(error, SEVERITY.WARNING, 'Deprecation'),
);
return validationErrorAnnotations.concat(deprecationWarningAnnotations);
}
} catch (error) {
const range = getRange(
error.locations[0],
queryText,
);
return [{
severity: SEVERITY.ERROR,
message: error.message,
source: 'GraphQL: Syntax',
range,
}];
}
const errors: Array = schema ?
validateWithCustomRules(schema, ast, customRules) : [];
return mapCat(errors, error => errorAnnotations(error));
}