graphql-codegen-visitor-plugin-common
Advanced tools
Comparing version 0.19.0-alpha.35980e3e to 0.19.0-alpha.89ed12b6
@@ -19,2 +19,12 @@ "use strict"; | ||
var variables_to_object_1 = require("./variables-to-object"); | ||
function getRootType(operation, schema) { | ||
switch (operation) { | ||
case 'query': | ||
return schema.getQueryType(); | ||
case 'mutation': | ||
return schema.getMutationType(); | ||
case 'subscription': | ||
return schema.getSubscriptionType(); | ||
} | ||
} | ||
var BaseDocumentsVisitor = /** @class */ (function () { | ||
@@ -38,3 +48,3 @@ function BaseDocumentsVisitor(rawConfig, additionalConfig, _schema, defaultScalars) { | ||
var name = _this.handleAnonymouseOperation(node.name && node.name.value ? node.name.value : null); | ||
var operationRootType = _this._schema.getType(utils_1.toPascalCase(node.operation)); | ||
var operationRootType = getRootType(node.operation, _this._schema); | ||
var selectionSet = _this._selectionSetToObject.createNext(operationRootType, node.selectionSet); | ||
@@ -41,0 +51,0 @@ var visitedOperationVariables = _this._variablesTransfomer.transform(node.variableDefinitions); |
@@ -5,2 +5,14 @@ "use strict"; | ||
var utils_1 = require("./utils"); | ||
function isMetadataFieldName(name) { | ||
return ['__schema', '__type'].includes(name); | ||
} | ||
function isRootType(type, schema) { | ||
return (graphql_1.isEqualType(type, schema.getQueryType()) || | ||
graphql_1.isEqualType(type, schema.getMutationType()) || | ||
graphql_1.isEqualType(type, schema.getSubscriptionType())); | ||
} | ||
var metadataFieldMap = { | ||
__schema: graphql_1.SchemaMetaFieldDef, | ||
__type: graphql_1.TypeMetaFieldDef | ||
}; | ||
var SelectionSetToObject = /** @class */ (function () { | ||
@@ -33,3 +45,9 @@ function SelectionSetToObject(_scalars, _schema, _convertName, _addTypename, _parentSchemaType, _selectionSet) { | ||
if (graphql_1.isObjectType(this._parentSchemaType) || graphql_1.isInterfaceType(this._parentSchemaType)) { | ||
var schemaField = this._parentSchemaType.getFields()[field.name.value]; | ||
var schemaField = void 0; | ||
if (isRootType(this._parentSchemaType, this._schema) && isMetadataFieldName(field.name.value)) { | ||
schemaField = metadataFieldMap[field.name.value]; | ||
} | ||
else { | ||
schemaField = this._parentSchemaType.getFields()[field.name.value]; | ||
} | ||
var rawType = schemaField.type; | ||
@@ -36,0 +54,0 @@ var baseType = utils_1.getBaseType(rawType); |
{ | ||
"name": "graphql-codegen-visitor-plugin-common", | ||
"version": "0.19.0-alpha.35980e3e", | ||
"version": "0.19.0-alpha.89ed12b6", | ||
"license": "MIT", | ||
@@ -10,3 +10,3 @@ "scripts": { | ||
"auto-bind": "2.0.0", | ||
"graphql-codegen-core": "0.19.0-alpha.35980e3e" | ||
"graphql-codegen-core": "0.19.0-alpha.89ed12b6" | ||
}, | ||
@@ -13,0 +13,0 @@ "peerDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
87546
363
1219
+ Addedgraphql-codegen-core@0.19.0-alpha.89ed12b6(transitive)
- Removedgraphql-codegen-core@0.19.0-alpha.35980e3e(transitive)