@grapes-agency/apollo-link-local-schema
Advanced tools
Comparing version 1.0.0-alpha.24 to 1.0.0-alpha.25
@@ -6,2 +6,13 @@ # Change Log | ||
# [1.0.0-alpha.25](https://github.com/grapes-agency/graphql/compare/@grapes-agency/apollo-link-local-schema@1.0.0-alpha.24...@grapes-agency/apollo-link-local-schema@1.0.0-alpha.25) (2020-11-06) | ||
### Features | ||
* **apollo-link-local-schema:** Support introspection for federated link without query type ([07ec58c](https://github.com/grapes-agency/graphql/commit/07ec58c15647a9c1bdf201790aec8f8bd50374b3)) | ||
# [1.0.0-alpha.24](https://github.com/grapes-agency/graphql/compare/@grapes-agency/apollo-link-local-schema@1.0.0-alpha.23...@grapes-agency/apollo-link-local-schema@1.0.0-alpha.24) (2020-11-05) | ||
@@ -8,0 +19,0 @@ |
@@ -57,7 +57,7 @@ 'use strict'; | ||
: {})))); | ||
const createIntrospectionResolvers = (typeDefs, { includeObjectTypeExtensions = false } = {}) => { | ||
const createIntrospectionResolvers = (typeDefs, { federated = false } = {}) => { | ||
const schemaDefinition = typeDefs.definitions.find(helpers.isSchemaDefinition); | ||
const typesMap = new Map([ | ||
...specifiedScalarTypeDefinitions, | ||
...typeDefs.definitions.filter(type => isTypeDefinition(type) || (includeObjectTypeExtensions && helpers.isObjectTypeExtension(type))), | ||
...typeDefs.definitions.filter(type => isTypeDefinition(type) || (federated && helpers.isObjectTypeExtension(type))), | ||
].map(definition => [definition.name.value, definition])); | ||
@@ -74,3 +74,13 @@ return { | ||
const queryTypeName = ((_a = schemaDefinition === null || schemaDefinition === void 0 ? void 0 : schemaDefinition.operationTypes.find(operationType => operationType.operation === 'query')) === null || _a === void 0 ? void 0 : _a.type.name.value) || 'Query'; | ||
return typesMap.get(queryTypeName); | ||
if (typesMap.has(queryTypeName)) { | ||
return typesMap.get(queryTypeName); | ||
} | ||
if (!federated) { | ||
return null; | ||
} | ||
const fakeQueryType = { | ||
kind: 'ObjectTypeDefinition', | ||
name: { kind: 'Name', value: 'Query' }, | ||
}; | ||
return fakeQueryType; | ||
}, | ||
@@ -407,3 +417,3 @@ mutationType: () => { | ||
if (introspection) { | ||
resolversArray.unshift(createIntrospectionResolvers(mergedTypeDefs, { includeObjectTypeExtensions: Boolean(this.federated) })); | ||
resolversArray.unshift(createIntrospectionResolvers(mergedTypeDefs, { federated: Boolean(this.federated) })); | ||
mergedTypeDefs = mergeDocuments([introspectionTypeDefs, mergedTypeDefs]); | ||
@@ -410,0 +420,0 @@ } |
import type { Resolvers } from '@grapes-agency/tiny-graphql-runtime'; | ||
import { DocumentNode } from 'graphql'; | ||
interface Options { | ||
includeObjectTypeExtensions?: boolean; | ||
federated?: boolean; | ||
} | ||
export declare const createIntrospectionResolvers: (typeDefs: DocumentNode, { includeObjectTypeExtensions }?: Options) => Resolvers; | ||
export declare const createIntrospectionResolvers: (typeDefs: DocumentNode, { federated }?: Options) => Resolvers; | ||
export {}; |
@@ -24,7 +24,7 @@ import { isSchemaDefinition, isObjectTypeExtension, isDirectiveDefinition, isObjectTypeDefinition, isInterfaceTypeDefinition, isUnionTypeDefinition, isEnumTypeDefinition, isInputObjectTypeDefinition, isListType, isNonNullType } from '@grapes-agency/tiny-graphql-runtime/helpers'; | ||
: {})))); | ||
const createIntrospectionResolvers = (typeDefs, { includeObjectTypeExtensions = false } = {}) => { | ||
const createIntrospectionResolvers = (typeDefs, { federated = false } = {}) => { | ||
const schemaDefinition = typeDefs.definitions.find(isSchemaDefinition); | ||
const typesMap = new Map([ | ||
...specifiedScalarTypeDefinitions, | ||
...typeDefs.definitions.filter(type => isTypeDefinition(type) || (includeObjectTypeExtensions && isObjectTypeExtension(type))), | ||
...typeDefs.definitions.filter(type => isTypeDefinition(type) || (federated && isObjectTypeExtension(type))), | ||
].map(definition => [definition.name.value, definition])); | ||
@@ -41,3 +41,13 @@ return { | ||
const queryTypeName = ((_a = schemaDefinition === null || schemaDefinition === void 0 ? void 0 : schemaDefinition.operationTypes.find(operationType => operationType.operation === 'query')) === null || _a === void 0 ? void 0 : _a.type.name.value) || 'Query'; | ||
return typesMap.get(queryTypeName); | ||
if (typesMap.has(queryTypeName)) { | ||
return typesMap.get(queryTypeName); | ||
} | ||
if (!federated) { | ||
return null; | ||
} | ||
const fakeQueryType = { | ||
kind: 'ObjectTypeDefinition', | ||
name: { kind: 'Name', value: 'Query' }, | ||
}; | ||
return fakeQueryType; | ||
}, | ||
@@ -44,0 +54,0 @@ mutationType: () => { |
@@ -29,3 +29,3 @@ import { ApolloLink, Observable } from '@apollo/client/core'; | ||
if (introspection) { | ||
resolversArray.unshift(createIntrospectionResolvers(mergedTypeDefs, { includeObjectTypeExtensions: Boolean(this.federated) })); | ||
resolversArray.unshift(createIntrospectionResolvers(mergedTypeDefs, { federated: Boolean(this.federated) })); | ||
mergedTypeDefs = mergeDocuments([introspectionTypeDefs, mergedTypeDefs]); | ||
@@ -32,0 +32,0 @@ } |
{ | ||
"name": "@grapes-agency/apollo-link-local-schema", | ||
"version": "1.0.0-alpha.24", | ||
"version": "1.0.0-alpha.25", | ||
"description": "Lightweight local schema resolver for @apollo/client", | ||
@@ -5,0 +5,0 @@ "main": "index.cjs.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
164832
1298