relay-compiler 9.0.0 → 9.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/bin/RelayCompilerBin.js.flow +169 -0
- package/bin/RelayCompilerMain.js.flow +508 -0
- package/bin/__fixtures__/plugin-module.js.flow +17 -0
- package/bin/relay-compiler +2002 -1733
- package/codegen/CodegenDirectory.js.flow +375 -0
- package/codegen/CodegenRunner.js.flow +431 -0
- package/codegen/CodegenTypes.js.flow +28 -0
- package/codegen/CodegenWatcher.js.flow +254 -0
- package/codegen/NormalizationCodeGenerator.js.flow +499 -0
- package/codegen/ReaderCodeGenerator.js.flow +453 -0
- package/codegen/RelayCodeGenerator.js.flow +76 -0
- package/codegen/RelayFileWriter.js.flow +366 -0
- package/codegen/SourceControl.js.flow +58 -0
- package/codegen/compileRelayArtifacts.js.flow +182 -0
- package/codegen/createPrintRequireModuleDependency.js.flow +21 -0
- package/codegen/writeRelayGeneratedFile.js.flow +194 -0
- package/core/ASTCache.js.flow +73 -0
- package/core/ASTConvert.js.flow +233 -0
- package/core/CompilerContext.js.flow +190 -0
- package/core/CompilerError.js.flow +250 -0
- package/core/DotGraphQLParser.js.flow +39 -0
- package/core/GraphQLCompilerProfiler.js.flow +341 -0
- package/core/GraphQLDerivedFromMetadata.js.flow +48 -0
- package/core/GraphQLWatchmanClient.js.flow +111 -0
- package/core/IR.js.flow +329 -0
- package/core/IRPrinter.js.flow +488 -0
- package/core/IRTransformer.js.flow +377 -0
- package/core/IRValidator.js.flow +260 -0
- package/core/IRVisitor.js.flow +150 -0
- package/core/JSModuleParser.js.flow +24 -0
- package/core/RelayCompilerScope.js.flow +199 -0
- package/core/RelayFindGraphQLTags.js.flow +119 -0
- package/core/RelayGraphQLEnumsGenerator.js.flow +55 -0
- package/core/RelayIRTransforms.js.flow +130 -0
- package/core/RelayParser.js.flow +1759 -0
- package/core/RelaySourceModuleParser.js.flow +135 -0
- package/core/Schema.js.flow +1985 -0
- package/core/SchemaUtils.js.flow +109 -0
- package/core/filterContextForNode.js.flow +50 -0
- package/core/getFieldDefinition.js.flow +156 -0
- package/core/getIdentifierForArgumentValue.js.flow +49 -0
- package/core/getIdentifierForSelection.js.flow +69 -0
- package/core/getLiteralArgumentValues.js.flow +32 -0
- package/core/getNormalizationOperationName.js.flow +19 -0
- package/core/inferRootArgumentDefinitions.js.flow +323 -0
- package/index.js +1 -1
- package/index.js.flow +202 -0
- package/language/RelayLanguagePluginInterface.js.flow +283 -0
- package/language/javascript/FindGraphQLTags.js.flow +233 -0
- package/language/javascript/RelayFlowBabelFactories.js.flow +180 -0
- package/language/javascript/RelayFlowGenerator.js.flow +1040 -0
- package/language/javascript/RelayFlowTypeTransformers.js.flow +184 -0
- package/language/javascript/RelayLanguagePluginJavaScript.js.flow +34 -0
- package/language/javascript/formatGeneratedModule.js.flow +65 -0
- package/lib/bin/RelayCompilerBin.js +10 -0
- package/lib/bin/RelayCompilerMain.js +113 -119
- package/lib/codegen/CodegenDirectory.js +2 -6
- package/lib/codegen/CodegenRunner.js +34 -75
- package/lib/codegen/CodegenWatcher.js +13 -21
- package/lib/codegen/NormalizationCodeGenerator.js +43 -40
- package/lib/codegen/ReaderCodeGenerator.js +43 -35
- package/lib/codegen/RelayCodeGenerator.js +7 -5
- package/lib/codegen/RelayFileWriter.js +15 -36
- package/lib/codegen/compileRelayArtifacts.js +16 -30
- package/lib/codegen/writeRelayGeneratedFile.js +56 -98
- package/lib/core/ASTCache.js +1 -3
- package/lib/core/CompilerContext.js +1 -3
- package/lib/core/CompilerError.js +27 -54
- package/lib/core/GraphQLCompilerProfiler.js +8 -12
- package/lib/core/GraphQLWatchmanClient.js +4 -12
- package/lib/core/IRPrinter.js +5 -5
- package/lib/core/IRTransformer.js +8 -6
- package/lib/core/IRValidator.js +1 -3
- package/lib/core/RelayCompilerScope.js +4 -4
- package/lib/core/RelayGraphQLEnumsGenerator.js +12 -15
- package/lib/core/RelayIRTransforms.js +9 -5
- package/lib/core/RelayParser.js +44 -56
- package/lib/core/RelaySourceModuleParser.js +1 -3
- package/lib/core/Schema.js +78 -65
- package/lib/core/getFieldDefinition.js +12 -15
- package/lib/core/getIdentifierForSelection.js +1 -1
- package/lib/core/inferRootArgumentDefinitions.js +27 -36
- package/lib/language/javascript/RelayFlowGenerator.js +49 -78
- package/lib/language/javascript/RelayFlowTypeTransformers.js +1 -3
- package/lib/reporters/ConsoleReporter.js +1 -3
- package/lib/reporters/MultiReporter.js +1 -3
- package/lib/runner/Artifacts.js +69 -170
- package/lib/runner/BufferedFilesystem.js +32 -66
- package/lib/runner/GraphQLASTNodeGroup.js +54 -120
- package/lib/runner/GraphQLNodeMap.js +14 -19
- package/lib/runner/Sources.js +49 -78
- package/lib/runner/StrictMap.js +20 -36
- package/lib/runner/getChangedNodeNames.js +30 -62
- package/lib/transforms/ApplyFragmentArgumentTransform.js +33 -28
- package/lib/transforms/ClientExtensionsTransform.js +7 -12
- package/lib/transforms/ConnectionTransform.js +26 -24
- package/lib/transforms/DeferStreamTransform.js +20 -16
- package/lib/transforms/DisallowTypenameOnRoot.js +55 -0
- package/lib/transforms/FieldHandleTransform.js +6 -2
- package/lib/transforms/FlattenTransform.js +19 -14
- package/lib/transforms/GenerateIDFieldTransform.js +7 -3
- package/lib/transforms/GenerateTypeNameTransform.js +6 -2
- package/lib/transforms/InlineDataFragmentTransform.js +7 -3
- package/lib/transforms/MaskTransform.js +17 -17
- package/lib/transforms/MatchTransform.js +110 -32
- package/lib/transforms/RefetchableFragmentTransform.js +21 -17
- package/lib/transforms/RelayDirectiveTransform.js +11 -3
- package/lib/transforms/SkipClientExtensionsTransform.js +8 -0
- package/lib/transforms/SkipHandleFieldTransform.js +6 -2
- package/lib/transforms/SkipRedundantNodesTransform.js +6 -2
- package/lib/transforms/SkipSplitOperationTransform.js +32 -0
- package/lib/transforms/SkipUnreachableNodeTransform.js +9 -2
- package/lib/transforms/SkipUnusedVariablesTransform.js +18 -17
- package/lib/transforms/SplitModuleImportTransform.js +2 -2
- package/lib/transforms/TestOperationTransform.js +7 -3
- package/lib/transforms/ValidateGlobalVariablesTransform.js +18 -30
- package/lib/transforms/ValidateRequiredArgumentsTransform.js +12 -15
- package/lib/transforms/ValidateServerOnlyDirectivesTransform.js +16 -30
- package/lib/transforms/ValidateUnusedVariablesTransform.js +18 -30
- package/lib/transforms/query-generators/FetchableQueryGenerator.js +161 -0
- package/lib/transforms/query-generators/NodeQueryGenerator.js +7 -2
- package/lib/transforms/query-generators/QueryQueryGenerator.js +1 -0
- package/lib/transforms/query-generators/ViewerQueryGenerator.js +1 -0
- package/lib/transforms/query-generators/index.js +23 -6
- package/lib/transforms/query-generators/utils.js +12 -15
- package/lib/util/RelayCompilerCache.js +1 -3
- package/lib/util/dedupeJSONStringify.js +15 -12
- package/lib/util/getModuleName.js +1 -1
- package/package.json +2 -2
- package/relay-compiler.js +4 -4
- package/relay-compiler.min.js +4 -4
- package/reporters/ConsoleReporter.js.flow +81 -0
- package/reporters/MultiReporter.js.flow +43 -0
- package/reporters/Reporter.js.flow +19 -0
- package/runner/Artifacts.js.flow +219 -0
- package/runner/BufferedFilesystem.js.flow +194 -0
- package/runner/GraphQLASTNodeGroup.js.flow +176 -0
- package/runner/GraphQLASTUtils.js.flow +26 -0
- package/runner/GraphQLNodeMap.js.flow +55 -0
- package/runner/Sources.js.flow +218 -0
- package/runner/StrictMap.js.flow +96 -0
- package/runner/compileArtifacts.js.flow +76 -0
- package/runner/extractAST.js.flow +100 -0
- package/runner/getChangedNodeNames.js.flow +48 -0
- package/runner/getSchemaInstance.js.flow +36 -0
- package/runner/types.js.flow +37 -0
- package/transforms/ApplyFragmentArgumentTransform.js.flow +474 -0
- package/transforms/ClientExtensionsTransform.js.flow +220 -0
- package/transforms/ConnectionTransform.js.flow +869 -0
- package/transforms/DeferStreamTransform.js.flow +258 -0
- package/transforms/DisallowIdAsAlias.js.flow +47 -0
- package/transforms/DisallowTypenameOnRoot.js.flow +45 -0
- package/transforms/FieldHandleTransform.js.flow +80 -0
- package/transforms/FilterDirectivesTransform.js.flow +45 -0
- package/transforms/FlattenTransform.js.flow +456 -0
- package/transforms/GenerateIDFieldTransform.js.flow +134 -0
- package/transforms/GenerateTypeNameTransform.js.flow +81 -0
- package/transforms/InlineDataFragmentTransform.js.flow +124 -0
- package/transforms/InlineFragmentsTransform.js.flow +71 -0
- package/transforms/MaskTransform.js.flow +126 -0
- package/transforms/MatchTransform.js.flow +583 -0
- package/transforms/RefetchableFragmentTransform.js.flow +272 -0
- package/transforms/RelayDirectiveTransform.js.flow +99 -0
- package/transforms/SkipClientExtensionsTransform.js.flow +54 -0
- package/transforms/SkipHandleFieldTransform.js.flow +44 -0
- package/transforms/SkipRedundantNodesTransform.js.flow +253 -0
- package/transforms/SkipSplitOperationTransform.js.flow +37 -0
- package/transforms/SkipUnreachableNodeTransform.js.flow +149 -0
- package/transforms/SkipUnusedVariablesTransform.js.flow +59 -0
- package/transforms/SplitModuleImportTransform.js.flow +98 -0
- package/transforms/TestOperationTransform.js.flow +138 -0
- package/transforms/TransformUtils.js.flow +26 -0
- package/transforms/ValidateGlobalVariablesTransform.js.flow +81 -0
- package/transforms/ValidateRequiredArgumentsTransform.js.flow +127 -0
- package/transforms/ValidateServerOnlyDirectivesTransform.js.flow +112 -0
- package/transforms/ValidateUnusedVariablesTransform.js.flow +89 -0
- package/transforms/query-generators/FetchableQueryGenerator.js.flow +190 -0
- package/transforms/query-generators/NodeQueryGenerator.js.flow +206 -0
- package/transforms/query-generators/QueryQueryGenerator.js.flow +57 -0
- package/transforms/query-generators/ViewerQueryGenerator.js.flow +97 -0
- package/transforms/query-generators/index.js.flow +90 -0
- package/transforms/query-generators/utils.js.flow +72 -0
- package/util/CodeMarker.js.flow +79 -0
- package/util/DefaultHandleKey.js.flow +17 -0
- package/util/RelayCompilerCache.js.flow +88 -0
- package/util/Rollout.js.flow +39 -0
- package/util/TimeReporter.js.flow +79 -0
- package/util/areEqualOSS.js.flow +123 -0
- package/util/dedupeJSONStringify.js.flow +152 -0
- package/util/getDefinitionNodeHash.js.flow +25 -0
- package/util/getModuleName.js.flow +39 -0
- package/util/joinArgumentDefinitions.js.flow +99 -0
- package/util/md5.js.flow +22 -0
- package/util/murmurHash.js.flow +94 -0
- package/util/nullthrowsOSS.js.flow +25 -0
- package/util/orList.js.flow +37 -0
- package/util/partitionArray.js.flow +37 -0
@@ -0,0 +1,109 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
* @flow strict
|
8
|
+
* @format
|
9
|
+
*/
|
10
|
+
|
11
|
+
// flowlint ambiguous-object-type:error
|
12
|
+
|
13
|
+
'use strict';
|
14
|
+
|
15
|
+
import type {ScalarField} from '../core/IR';
|
16
|
+
import type {ScalarFieldTypeID} from './Schema';
|
17
|
+
import type {Schema, InputTypeID} from './Schema';
|
18
|
+
import type {ASTNode} from 'graphql';
|
19
|
+
|
20
|
+
const ID = 'id';
|
21
|
+
|
22
|
+
/**
|
23
|
+
* @public
|
24
|
+
*
|
25
|
+
* Determine if an AST node contains a fragment/operation definition.
|
26
|
+
*/
|
27
|
+
function isExecutableDefinitionAST(ast: ASTNode): boolean %checks {
|
28
|
+
return (
|
29
|
+
ast.kind === 'FragmentDefinition' || ast.kind === 'OperationDefinition'
|
30
|
+
);
|
31
|
+
}
|
32
|
+
|
33
|
+
/**
|
34
|
+
* @public
|
35
|
+
*
|
36
|
+
* Determine if an AST node contains a schema definition.
|
37
|
+
*/
|
38
|
+
function isSchemaDefinitionAST(ast: ASTNode): boolean %checks {
|
39
|
+
return (
|
40
|
+
ast.kind === 'SchemaDefinition' ||
|
41
|
+
ast.kind === 'ScalarTypeDefinition' ||
|
42
|
+
ast.kind === 'ObjectTypeDefinition' ||
|
43
|
+
ast.kind === 'InterfaceTypeDefinition' ||
|
44
|
+
ast.kind === 'UnionTypeDefinition' ||
|
45
|
+
ast.kind === 'EnumTypeDefinition' ||
|
46
|
+
ast.kind === 'InputObjectTypeDefinition' ||
|
47
|
+
ast.kind === 'DirectiveDefinition' ||
|
48
|
+
ast.kind === 'ScalarTypeExtension' ||
|
49
|
+
ast.kind === 'ObjectTypeExtension' ||
|
50
|
+
ast.kind === 'InterfaceTypeExtension' ||
|
51
|
+
ast.kind === 'UnionTypeExtension' ||
|
52
|
+
ast.kind === 'EnumTypeExtension' ||
|
53
|
+
ast.kind === 'InputObjectTypeExtension'
|
54
|
+
);
|
55
|
+
}
|
56
|
+
|
57
|
+
function generateIDField(idType: ScalarFieldTypeID): ScalarField {
|
58
|
+
return {
|
59
|
+
kind: 'ScalarField',
|
60
|
+
alias: ID,
|
61
|
+
args: [],
|
62
|
+
directives: [],
|
63
|
+
handles: null,
|
64
|
+
loc: {kind: 'Generated'},
|
65
|
+
metadata: null,
|
66
|
+
name: ID,
|
67
|
+
type: idType,
|
68
|
+
};
|
69
|
+
}
|
70
|
+
|
71
|
+
function getNullableBooleanInput(schema: Schema): InputTypeID {
|
72
|
+
return schema.assertInputType(schema.expectBooleanType());
|
73
|
+
}
|
74
|
+
|
75
|
+
function getNonNullBooleanInput(schema: Schema): InputTypeID {
|
76
|
+
return schema.assertInputType(
|
77
|
+
schema.getNonNullType(schema.expectBooleanType()),
|
78
|
+
);
|
79
|
+
}
|
80
|
+
|
81
|
+
function getNullableStringInput(schema: Schema): InputTypeID {
|
82
|
+
return schema.assertInputType(schema.expectStringType());
|
83
|
+
}
|
84
|
+
|
85
|
+
function getNonNullStringInput(schema: Schema): InputTypeID {
|
86
|
+
return schema.assertInputType(
|
87
|
+
schema.getNonNullType(schema.expectStringType()),
|
88
|
+
);
|
89
|
+
}
|
90
|
+
|
91
|
+
function getNullableIdInput(schema: Schema): InputTypeID {
|
92
|
+
return schema.assertInputType(schema.expectIdType());
|
93
|
+
}
|
94
|
+
|
95
|
+
function getNonNullIdInput(schema: Schema): InputTypeID {
|
96
|
+
return schema.assertInputType(schema.getNonNullType(schema.expectIdType()));
|
97
|
+
}
|
98
|
+
|
99
|
+
module.exports = {
|
100
|
+
generateIDField,
|
101
|
+
isExecutableDefinitionAST,
|
102
|
+
isSchemaDefinitionAST,
|
103
|
+
getNullableBooleanInput,
|
104
|
+
getNonNullBooleanInput,
|
105
|
+
getNullableStringInput,
|
106
|
+
getNonNullStringInput,
|
107
|
+
getNullableIdInput,
|
108
|
+
getNonNullIdInput,
|
109
|
+
};
|
@@ -0,0 +1,50 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
* @flow strict
|
8
|
+
* @format
|
9
|
+
*/
|
10
|
+
|
11
|
+
// flowlint ambiguous-object-type:error
|
12
|
+
|
13
|
+
'use strict';
|
14
|
+
|
15
|
+
const CompilerContext = require('./CompilerContext');
|
16
|
+
|
17
|
+
const {visit} = require('./IRVisitor');
|
18
|
+
|
19
|
+
import type {Fragment, FragmentSpread, Root} from './IR';
|
20
|
+
|
21
|
+
/**
|
22
|
+
* Returns a CompilerContext containing only the documents referenced
|
23
|
+
* by and including the provided node.
|
24
|
+
*/
|
25
|
+
function filterContextForNode(
|
26
|
+
node: Fragment | Root,
|
27
|
+
context: CompilerContext,
|
28
|
+
): CompilerContext {
|
29
|
+
const queue = [node];
|
30
|
+
let filteredContext = new CompilerContext(context.getSchema()).add(node);
|
31
|
+
const visitFragmentSpread = (fragmentSpread: FragmentSpread) => {
|
32
|
+
const {name} = fragmentSpread;
|
33
|
+
if (!filteredContext.get(name)) {
|
34
|
+
const fragment = context.getFragment(name);
|
35
|
+
filteredContext = filteredContext.add(fragment);
|
36
|
+
queue.push(fragment);
|
37
|
+
}
|
38
|
+
};
|
39
|
+
const visitorConfig = {
|
40
|
+
FragmentSpread: (fragmentSpread: FragmentSpread) => {
|
41
|
+
visitFragmentSpread(fragmentSpread);
|
42
|
+
},
|
43
|
+
};
|
44
|
+
while (queue.length) {
|
45
|
+
visit(queue.pop(), visitorConfig);
|
46
|
+
}
|
47
|
+
return filteredContext;
|
48
|
+
}
|
49
|
+
|
50
|
+
module.exports = filterContextForNode;
|
@@ -0,0 +1,156 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
* @flow strict
|
8
|
+
* @format
|
9
|
+
*/
|
10
|
+
|
11
|
+
// flowlint ambiguous-object-type:error
|
12
|
+
|
13
|
+
'use strict';
|
14
|
+
|
15
|
+
const {createCompilerError} = require('./CompilerError');
|
16
|
+
const {SchemaMetaFieldDef, TypeMetaFieldDef} = require('graphql');
|
17
|
+
|
18
|
+
import type {Schema, TypeID, FieldID} from './Schema';
|
19
|
+
import type {FieldNode} from 'graphql';
|
20
|
+
|
21
|
+
export type GetFieldDefinitionFn = (
|
22
|
+
schema: Schema,
|
23
|
+
parentType: TypeID,
|
24
|
+
fieldName: string,
|
25
|
+
fieldAST: FieldNode,
|
26
|
+
) => ?FieldID;
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Find the definition of a field of the specified type using strict
|
30
|
+
* resolution rules per the GraphQL spec.
|
31
|
+
*/
|
32
|
+
function getFieldDefinitionStrict(
|
33
|
+
schema: Schema,
|
34
|
+
parentType: TypeID,
|
35
|
+
fieldName: string,
|
36
|
+
): ?FieldID {
|
37
|
+
const type = schema.getRawType(parentType);
|
38
|
+
const queryType = schema.getQueryType();
|
39
|
+
const isQueryType =
|
40
|
+
queryType != null && schema.areEqualTypes(type, queryType);
|
41
|
+
const hasTypeName = schema.isAbstractType(type) || schema.isObject(type);
|
42
|
+
|
43
|
+
let schemaFieldDef;
|
44
|
+
if (isQueryType && fieldName === SchemaMetaFieldDef.name) {
|
45
|
+
schemaFieldDef =
|
46
|
+
queryType != null ? schema.getFieldByName(queryType, '__schema') : null;
|
47
|
+
} else if (isQueryType && fieldName === TypeMetaFieldDef.name) {
|
48
|
+
schemaFieldDef =
|
49
|
+
queryType != null ? schema.getFieldByName(queryType, '__type') : null;
|
50
|
+
} else if (hasTypeName && fieldName === '__typename') {
|
51
|
+
schemaFieldDef = schema.getFieldByName(
|
52
|
+
schema.assertCompositeType(type),
|
53
|
+
'__typename',
|
54
|
+
);
|
55
|
+
} else if (hasTypeName && fieldName === '__id') {
|
56
|
+
schemaFieldDef = schema.getFieldByName(
|
57
|
+
schema.assertCompositeType(type),
|
58
|
+
'__id',
|
59
|
+
);
|
60
|
+
} else if (schema.isInterface(type) || schema.isObject(type)) {
|
61
|
+
const compositeType = schema.assertCompositeType(type);
|
62
|
+
if (schema.hasField(compositeType, fieldName)) {
|
63
|
+
schemaFieldDef = schema.getFieldByName(compositeType, fieldName);
|
64
|
+
} else {
|
65
|
+
return null;
|
66
|
+
}
|
67
|
+
}
|
68
|
+
return schemaFieldDef;
|
69
|
+
}
|
70
|
+
|
71
|
+
/**
|
72
|
+
* Find the definition of a field of the specified type, first trying
|
73
|
+
* the standard spec-compliant resolution process and falling back
|
74
|
+
* to legacy mode that supports fat interfaces.
|
75
|
+
*/
|
76
|
+
function getFieldDefinitionLegacy(
|
77
|
+
schema: Schema,
|
78
|
+
parentType: TypeID,
|
79
|
+
fieldName: string,
|
80
|
+
fieldAST: FieldNode,
|
81
|
+
): ?FieldID {
|
82
|
+
let schemaFieldDef = getFieldDefinitionStrict(schema, parentType, fieldName);
|
83
|
+
|
84
|
+
if (!schemaFieldDef) {
|
85
|
+
schemaFieldDef = getFieldDefinitionLegacyImpl(
|
86
|
+
schema,
|
87
|
+
parentType,
|
88
|
+
fieldName,
|
89
|
+
fieldAST,
|
90
|
+
);
|
91
|
+
}
|
92
|
+
return schemaFieldDef ?? null;
|
93
|
+
}
|
94
|
+
|
95
|
+
/**
|
96
|
+
* @private
|
97
|
+
*/
|
98
|
+
function getFieldDefinitionLegacyImpl(
|
99
|
+
schema: Schema,
|
100
|
+
type: TypeID,
|
101
|
+
fieldName: string,
|
102
|
+
fieldAST: FieldNode,
|
103
|
+
): ?FieldID {
|
104
|
+
const rawType = schema.getRawType(type);
|
105
|
+
if (
|
106
|
+
schema.isAbstractType(rawType) &&
|
107
|
+
fieldAST &&
|
108
|
+
fieldAST.directives &&
|
109
|
+
fieldAST.directives.some(
|
110
|
+
directive => getName(directive) === 'fixme_fat_interface',
|
111
|
+
)
|
112
|
+
) {
|
113
|
+
const possibleTypes = schema.getPossibleTypes(
|
114
|
+
schema.assertAbstractType(rawType),
|
115
|
+
);
|
116
|
+
let schemaFieldDef;
|
117
|
+
for (const possibleType of possibleTypes) {
|
118
|
+
const possibleField = schema.getFieldByName(possibleType, fieldName);
|
119
|
+
if (possibleField) {
|
120
|
+
// Fat interface fields can have differing arguments. Try to return
|
121
|
+
// a field with matching arguments, but still return a field if the
|
122
|
+
// arguments do not match.
|
123
|
+
schemaFieldDef = possibleField;
|
124
|
+
if (fieldAST && fieldAST.arguments) {
|
125
|
+
const argumentsAllExist = fieldAST.arguments.every(
|
126
|
+
argument =>
|
127
|
+
schema.getFieldArgByName(possibleField, getName(argument)) !=
|
128
|
+
null,
|
129
|
+
);
|
130
|
+
if (argumentsAllExist) {
|
131
|
+
break;
|
132
|
+
}
|
133
|
+
}
|
134
|
+
}
|
135
|
+
}
|
136
|
+
return schemaFieldDef;
|
137
|
+
}
|
138
|
+
}
|
139
|
+
|
140
|
+
/**
|
141
|
+
* @private
|
142
|
+
*/
|
143
|
+
function getName(ast): string {
|
144
|
+
const name = ast.name ? ast.name.value : null;
|
145
|
+
if (typeof name !== 'string') {
|
146
|
+
throw createCompilerError("Expected ast node to have a 'name'.", null, [
|
147
|
+
ast,
|
148
|
+
]);
|
149
|
+
}
|
150
|
+
return name;
|
151
|
+
}
|
152
|
+
|
153
|
+
module.exports = {
|
154
|
+
getFieldDefinitionLegacy,
|
155
|
+
getFieldDefinitionStrict,
|
156
|
+
};
|
@@ -0,0 +1,49 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
* @flow strict
|
8
|
+
* @format
|
9
|
+
*/
|
10
|
+
|
11
|
+
// flowlint ambiguous-object-type:error
|
12
|
+
|
13
|
+
'use strict';
|
14
|
+
|
15
|
+
const invariant = require('invariant');
|
16
|
+
|
17
|
+
import type {ArgumentValue} from './IR';
|
18
|
+
|
19
|
+
/**
|
20
|
+
* Generates an identifier for an argument value. The identifier is based on the
|
21
|
+
* structure/order of items and keys in the value.
|
22
|
+
*/
|
23
|
+
function getIdentifierForArgumentValue(value: ArgumentValue): mixed {
|
24
|
+
switch (value.kind) {
|
25
|
+
case 'Variable':
|
26
|
+
return {variable: value.variableName};
|
27
|
+
case 'Literal':
|
28
|
+
return {value: value.value};
|
29
|
+
case 'ListValue':
|
30
|
+
return {
|
31
|
+
list: value.items.map(item => getIdentifierForArgumentValue(item)),
|
32
|
+
};
|
33
|
+
case 'ObjectValue':
|
34
|
+
return {
|
35
|
+
object: value.fields.map(field => ({
|
36
|
+
name: field.name,
|
37
|
+
value: getIdentifierForArgumentValue(field.value),
|
38
|
+
})),
|
39
|
+
};
|
40
|
+
default:
|
41
|
+
invariant(
|
42
|
+
false,
|
43
|
+
'getIdentifierForArgumentValue(): Unsupported AST kind `%s`.',
|
44
|
+
value.kind,
|
45
|
+
);
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
module.exports = getIdentifierForArgumentValue;
|
@@ -0,0 +1,69 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
* @flow strict-local
|
8
|
+
* @format
|
9
|
+
*/
|
10
|
+
|
11
|
+
// flowlint ambiguous-object-type:error
|
12
|
+
|
13
|
+
'use strict';
|
14
|
+
|
15
|
+
const invariant = require('invariant');
|
16
|
+
|
17
|
+
const {printArguments, printDirectives} = require('./IRPrinter');
|
18
|
+
|
19
|
+
import type {Selection} from './IR';
|
20
|
+
import type {Schema} from './Schema';
|
21
|
+
|
22
|
+
/**
|
23
|
+
* Generates an identifier that is unique to a given selection: the alias for
|
24
|
+
* fields, the type for inline fragments, and a summary of the condition
|
25
|
+
* variable and passing value for conditions.
|
26
|
+
*/
|
27
|
+
function getIdentifierForSelection(schema: Schema, node: Selection): string {
|
28
|
+
if (node.kind === 'LinkedField' || node.kind === 'ScalarField') {
|
29
|
+
return 'Field: ' + node.directives.length === 0
|
30
|
+
? node.alias
|
31
|
+
: node.alias + printDirectives(schema, node.directives);
|
32
|
+
} else if (node.kind === 'FragmentSpread') {
|
33
|
+
return 'FragmentSpread:' + node.args.length === 0
|
34
|
+
? node.name
|
35
|
+
: node.name + printArguments(schema, node.args);
|
36
|
+
} else if (node.kind === 'ModuleImport') {
|
37
|
+
return 'ModuleImport:';
|
38
|
+
} else if (node.kind === 'Defer') {
|
39
|
+
return 'Defer:' + node.label;
|
40
|
+
} else if (node.kind === 'Stream') {
|
41
|
+
return 'Stream:' + node.label;
|
42
|
+
} else if (node.kind === 'InlineFragment') {
|
43
|
+
return (
|
44
|
+
'InlineFragment:' +
|
45
|
+
schema.getTypeString(node.typeCondition) +
|
46
|
+
printDirectives(schema, node.directives)
|
47
|
+
);
|
48
|
+
} else if (node.kind === 'ClientExtension') {
|
49
|
+
return 'ClientExtension:';
|
50
|
+
} else if (node.kind === 'InlineDataFragmentSpread') {
|
51
|
+
return 'InlineDataFragment:' + node.name;
|
52
|
+
} else if (node.kind === 'Condition') {
|
53
|
+
return (
|
54
|
+
'Condition:' +
|
55
|
+
(node.condition.kind === 'Variable'
|
56
|
+
? '$' + node.condition.variableName
|
57
|
+
: String(node.condition.value)) +
|
58
|
+
String(node.passingValue)
|
59
|
+
);
|
60
|
+
} else {
|
61
|
+
invariant(
|
62
|
+
false,
|
63
|
+
'getIdentifierForSelection: Unexpected kind `%s`.',
|
64
|
+
(node.kind: empty),
|
65
|
+
);
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
69
|
+
module.exports = getIdentifierForSelection;
|
@@ -0,0 +1,32 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
* @flow strict
|
8
|
+
* @format
|
9
|
+
*/
|
10
|
+
|
11
|
+
// flowlint ambiguous-object-type:error
|
12
|
+
|
13
|
+
'use strict';
|
14
|
+
|
15
|
+
import type {Argument} from './IR';
|
16
|
+
|
17
|
+
// Copy of Variables type from '../../../react-relay/classic/tools/RelayTypes'
|
18
|
+
// Duplicating here rather than importing it since we can't take on a dependency
|
19
|
+
// outside of relay-compiler.
|
20
|
+
type Variables = {[name: string]: mixed, ...};
|
21
|
+
|
22
|
+
function getLiteralArgumentValues(args: $ReadOnlyArray<Argument>): Variables {
|
23
|
+
const values = {};
|
24
|
+
args.forEach(arg => {
|
25
|
+
if (arg.value.kind === 'Literal') {
|
26
|
+
values[arg.name] = arg.value.value;
|
27
|
+
}
|
28
|
+
});
|
29
|
+
return values;
|
30
|
+
}
|
31
|
+
|
32
|
+
module.exports = getLiteralArgumentValues;
|
@@ -0,0 +1,19 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
* @flow strict
|
8
|
+
* @format
|
9
|
+
*/
|
10
|
+
|
11
|
+
// flowlint ambiguous-object-type:error
|
12
|
+
|
13
|
+
'use strict';
|
14
|
+
|
15
|
+
function getNormalizationOperationName(name: string): string {
|
16
|
+
return `${name}$normalization`;
|
17
|
+
}
|
18
|
+
|
19
|
+
module.exports = getNormalizationOperationName;
|