1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | 'use strict';
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | function getFieldDefinitionStrict(schema, parentType, fieldName, fieldAST) {
|
17 | var type = require("./GraphQLSchemaUtils").getRawType(parentType);
|
18 |
|
19 | var isQueryType = type === schema.getQueryType();
|
20 |
|
21 | var hasTypeName = type instanceof require("graphql").GraphQLObjectType || type instanceof require("graphql").GraphQLInterfaceType || type instanceof require("graphql").GraphQLUnionType;
|
22 |
|
23 | var schemaFieldDef;
|
24 |
|
25 | if (isQueryType && fieldName === require("graphql").SchemaMetaFieldDef.name) {
|
26 | schemaFieldDef = require("graphql").SchemaMetaFieldDef;
|
27 | } else if (isQueryType && fieldName === require("graphql").TypeMetaFieldDef.name) {
|
28 | schemaFieldDef = require("graphql").TypeMetaFieldDef;
|
29 | } else if (hasTypeName && fieldName === require("graphql").TypeNameMetaFieldDef.name) {
|
30 | schemaFieldDef = require("graphql").TypeNameMetaFieldDef;
|
31 | } else if (type instanceof require("graphql").GraphQLInterfaceType || type instanceof require("graphql").GraphQLObjectType) {
|
32 | schemaFieldDef = type.getFields()[fieldName];
|
33 | }
|
34 |
|
35 | return schemaFieldDef;
|
36 | }
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | function getFieldDefinitionLegacy(schema, parentType, fieldName, fieldAST) {
|
45 | var schemaFieldDef = getFieldDefinitionStrict(schema, parentType, fieldName, fieldAST);
|
46 |
|
47 | if (!schemaFieldDef) {
|
48 | var type = require("./GraphQLSchemaUtils").getRawType(parentType);
|
49 |
|
50 | schemaFieldDef = getFieldDefinitionLegacyImpl(schema, type, fieldName, fieldAST);
|
51 | }
|
52 |
|
53 | return schemaFieldDef || null;
|
54 | }
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | function getFieldDefinitionLegacyImpl(schema, type, fieldName, fieldAST) {
|
61 | if (require("graphql").isAbstractType(type) && fieldAST && fieldAST.directives && fieldAST.directives.some(function (directive) {
|
62 | return getName(directive) === 'fixme_fat_interface';
|
63 | })) {
|
64 | var possibleTypes = schema.getPossibleTypes(require("graphql").assertAbstractType(type));
|
65 | var schemaFieldDef;
|
66 |
|
67 | var _loop = function _loop(ii) {
|
68 | var possibleField = possibleTypes[ii].getFields()[fieldName];
|
69 |
|
70 | if (possibleField) {
|
71 |
|
72 |
|
73 |
|
74 | schemaFieldDef = possibleField;
|
75 |
|
76 | if (fieldAST && fieldAST.arguments) {
|
77 | var argumentsAllExist = fieldAST.arguments.every(function (argument) {
|
78 | return possibleField.args.find(function (argDef) {
|
79 | return argDef.name === getName(argument);
|
80 | });
|
81 | });
|
82 |
|
83 | if (argumentsAllExist) {
|
84 | return "break";
|
85 | }
|
86 | }
|
87 | }
|
88 | };
|
89 |
|
90 | for (var ii = 0; ii < possibleTypes.length; ii++) {
|
91 | var _ret = _loop(ii);
|
92 |
|
93 | if (_ret === "break") break;
|
94 | }
|
95 |
|
96 | return schemaFieldDef;
|
97 | }
|
98 | }
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 | function getName(ast) {
|
105 | var name = ast.name ? ast.name.value : null;
|
106 |
|
107 | if (typeof name !== 'string') {
|
108 | throw require("./RelayCompilerError").createCompilerError("Expected ast node to have a 'name'.", null, [ast]);
|
109 | }
|
110 |
|
111 | return name;
|
112 | }
|
113 |
|
114 | module.exports = {
|
115 | getFieldDefinitionLegacy: getFieldDefinitionLegacy,
|
116 | getFieldDefinitionStrict: getFieldDefinitionStrict
|
117 | }; |
\ | No newline at end of file |