Skip to content
Permalink
Browse files

Remove RelayValidator

Reviewed By: kassens

Differential Revision: D17815205

fbshipit-source-id: d9a1fc7d5ee25b73bf16674b2b26a8c47ea36b9c
  • Loading branch information...
alunyov authored and facebook-github-bot committed Oct 10, 2019
1 parent 25c6769 commit 15e8d2201fdad47596e1acfb3a5daa3fb7511a8e
@@ -69,10 +69,6 @@ export type WriterConfig = {
// Haste style module that exports flow types for GraphQL enums.
// TODO(T22422153) support non-haste environments
enumsHasteModule?: string,
validationRules?: {
GLOBAL_RULES?: $ReadOnlyArray<ValidationRule>,
LOCAL_RULES?: $ReadOnlyArray<ValidationRule>,
},
printModuleDependency?: string => string,
filesystem?: Filesystem,
repersist?: boolean,
@@ -84,7 +80,6 @@ function compileAll({
schema,
compilerTransforms,
documents,
extraValidationRules,
reporter,
typeGenerator,
}: {|
@@ -93,27 +88,13 @@ function compileAll({
schema: Schema,
compilerTransforms: RelayCompilerTransforms,
documents: $ReadOnlyArray<DocumentNode>,
extraValidationRules?: {
GLOBAL_RULES?: $ReadOnlyArray<ValidationRule>,
LOCAL_RULES?: $ReadOnlyArray<ValidationRule>,
},
reporter: Reporter,
typeGenerator: TypeGenerator,
|}) {
// Verify using local and global rules, can run global verifications here
// because all files are processed together
const validationRules = extraValidationRules
? [
...(extraValidationRules.LOCAL_RULES || []),
...(extraValidationRules.GLOBAL_RULES || []),
]
: [];

const definitions = ASTConvert.convertASTDocumentsWithBase(
schema,
baseDocuments,
documents,
validationRules,
RelayParser.transform,
);
const compilerContext = new CompilerContext(schema).addAll(definitions);
@@ -172,7 +153,6 @@ function writeAll({
baseDocuments: baseDocuments.valueSeq().toArray(),
compilerTransforms: writerConfig.compilerTransforms,
documents: documents.valueSeq().toArray(),
extraValidationRules: writerConfig.validationRules,
reporter,
typeGenerator: writerConfig.typeGenerator,
});
@@ -11,7 +11,6 @@
'use strict';

const Profiler = require('./GraphQLCompilerProfiler');
const RelayValidator = require('./RelayValidator');

const {
isExecutableDefinitionAST,
@@ -30,7 +29,6 @@ import type {
OperationDefinitionNode,
TypeSystemDefinitionNode,
TypeSystemExtensionNode,
ValidationRule,
} from 'graphql';

type ASTDefinitionNode = FragmentDefinitionNode | OperationDefinitionNode;
@@ -42,7 +40,6 @@ type TransformFn = (
function convertASTDocuments(
schema: Schema,
documents: $ReadOnlyArray<DocumentNode>,
validationRules: $ReadOnlyArray<ValidationRule>,
transform: TransformFn,
): $ReadOnlyArray<Fragment | Root> {
return Profiler.run('ASTConvert.convertASTDocuments', () => {
@@ -57,20 +54,14 @@ function convertASTDocuments(
});
});

return convertASTDefinitions(
schema,
definitions,
validationRules,
transform,
);
return convertASTDefinitions(schema, definitions, transform);
});
}

function convertASTDocumentsWithBase(
schema: Schema,
baseDocuments: $ReadOnlyArray<DocumentNode>,
documents: $ReadOnlyArray<DocumentNode>,
validationRules: $ReadOnlyArray<ValidationRule>,
transform: TransformFn,
): $ReadOnlyArray<Fragment | Root> {
return Profiler.run('ASTConvert.convertASTDocumentsWithBase', () => {
@@ -127,19 +118,13 @@ function convertASTDocumentsWithBase(
requiredDefinitions.forEach(definition =>
definitionsToConvert.push(definition),
);
return convertASTDefinitions(
schema,
definitionsToConvert,
validationRules,
transform,
);
return convertASTDefinitions(schema, definitionsToConvert, transform);
});
}

function convertASTDefinitions(
schema: Schema,
definitions: $ReadOnlyArray<DefinitionNode>,
validationRules: $ReadOnlyArray<ValidationRule>,
transform: TransformFn,
): $ReadOnlyArray<Fragment | Root> {
const operationDefinitions: Array<ASTDefinitionNode> = [];
@@ -148,13 +133,6 @@ function convertASTDefinitions(
operationDefinitions.push(definition);
}
});

const validationAST = {
kind: 'Document',
definitions: operationDefinitions,
};
// Will throw an error if there are validation issues
RelayValidator.validate(schema, validationAST, validationRules);
return transform(schema, operationDefinitions);
}

This file was deleted.

@@ -30,18 +30,15 @@ const {
parse,
parseType,
print,
validate,
} = require('graphql');

import type {Field as GraphQLIRField} from './GraphQLIR';
import type {
DirectiveLocationEnum,
DocumentNode,
GraphQLArgument,
GraphQLError,
Source,
TypeNode,
ValidationRule,
ValueNode,
} from 'graphql';

@@ -1415,16 +1412,6 @@ class Schema {
return !this.isServerDefinedField(type, field);
}

/**
* This method should be replaced with the specific Relay validations
*/
DEPRECATED__validate(
document: DocumentNode,
rules: $ReadOnlyArray<ValidationRule>,
): $ReadOnlyArray<GraphQLError> {
return validate(this._extendedSchema, document, rules);
}

/**
* The only consumer of this is RelayParser.parse(...)
* We should either refactor RelayParser.parse(...) to not-rely on the `

This file was deleted.

This file was deleted.

@@ -35,7 +35,6 @@ const RelayIRValidations = require('./core/RelayIRValidations');
const RelayParser = require('./core/RelayParser');
const RelaySchema = require('./core/Schema');
const RelaySourceModuleParser = require('./core/RelaySourceModuleParser');
const RelayValidator = require('./core/RelayValidator');
const Rollout = require('./util/Rollout');
const SchemaUtils = require('./core/SchemaUtils');

@@ -143,7 +142,6 @@ module.exports = {

Parser: RelayParser,
Schema: RelaySchema,
Validator: RelayValidator,
CodeGenerator: RelayCodeGenerator,
FlowGenerator: RelayFlowGenerator,

@@ -28,7 +28,6 @@ function parseGraphQLText(
const definitions = convertASTDocuments(
Schema.DEPRECATED__create(schema, extendedSchema),
[ast],
[],
Parser.transform.bind(Parser),
);
return {

5 comments on commit 15e8d22

@mrtnzlml

This comment has been minimized.

Copy link
Contributor

mrtnzlml replied Oct 17, 2019

Hi @alunyov! Is here some replacement for the removed validationRules? We are using it for some extra validation rules. Thanks for your answer.

@alunyov

This comment has been minimized.

Copy link
Contributor Author

alunyov replied Oct 17, 2019

Hey, @mrtnzlml we've moved most of the GraphQL validation rules to RelayParser directly.

But some of them became a RelayTransforms - that doesn't change the IR, but validating the correctness of them.

For example (DisallowIdAsAlias): d55420b

The end-goal for us is to remove the dependency on the graphql-js schema implementation (which is used in GraphQL validations).

So, if you have extra validation rules, you can make them Relay Transforms. And configure the compiler to use these transforms.

Just our of curiosity, are those extra validation rules you mentioned will apply to Relay in general?

@mrtnzlml

This comment has been minimized.

Copy link
Contributor

mrtnzlml replied Oct 17, 2019

Thanks for the explanation! :)

Just our of curiosity, are those extra validation rules you mentioned will apply to Relay in general?

I don't think so. I am experimenting with it. We have basically two validators:

  • validation of deprecated fields, and
  • experimental result size validation

It looks like this:

Screenshot_2019-10-15_at_17 07 46

Deprecated fields could be even Eslint rule but the idea was to show warnings first and after some time (specified in deprecation reason?) we could start throwing an error. It would be more difficult with Eslint. Moreover, we could even automatically transform the fields into the new version.

The second validation is implementation of this idea: http://blog.liu.se/olafhartig/2018/08/08/lightweight-summary-of-our-paper-semantics-and-complexity-of-graphql/ (we will move it to the server, but I need it to figure out what should be the threshold for real-world queries).

So probably not useful at all for Relay community.

@alunyov

This comment has been minimized.

Copy link
Contributor Author

alunyov replied Oct 17, 2019

Yeah, you'll probably need to re-implement those as RelayTransform

For the second, I think, it's even better - because you can run it on already optimized (by compiler) queries, which will give you more accurate results.

@mrtnzlml

This comment has been minimized.

Copy link
Contributor

mrtnzlml replied Oct 17, 2019

For the second, I think, it's even better - because you can run it on already optimized (by compiler) queries, which will give you more accurate results.

Yes, definitely! I was trying to figure out how to run it on the transformed queries. Thank you very much! :)

Please sign in to comment.
You can’t perform that action at this time.