@graphql-inspector/loaders
Advanced tools
Comparing version 0.0.0-canary.8127707 to 0.0.0-canary.02a53c5
@@ -6,2 +6,3 @@ 'use strict'; | ||
const load = require('@graphql-tools/load'); | ||
const graphql = require('graphql'); | ||
@@ -12,6 +13,9 @@ class LoadersRegistry { | ||
} | ||
register(loaderName) { | ||
register(loader) { | ||
this.loaders.push(loader); | ||
} | ||
registerModule(loaderName) { | ||
try { | ||
const loader = loadModule(`@graphql-inspector/${loaderName}-loader`); | ||
this.loaders.push(loader); | ||
this.register(loader); | ||
} | ||
@@ -23,7 +27,56 @@ catch (error) { | ||
} | ||
loadSchema(pointer, options = {}) { | ||
return load.loadSchema(pointer, Object.assign({ loaders: this.loaders, assumeValid: true, assumeValidSDL: true }, options)); | ||
loadSchema(pointer, options = {}, enableApolloFederation, enableAWS) { | ||
return enrichError(load.loadSchema(pointer, Object.assign(Object.assign(Object.assign({ loaders: this.loaders }, options), (enableApolloFederation | ||
? { | ||
schemas: [ | ||
graphql.buildSchema(/* GraphQL */ ` | ||
scalar _FieldSet | ||
directive @external on FIELD_DEFINITION | ||
directive @requires(fields: _FieldSet!) on FIELD_DEFINITION | ||
directive @provides(fields: _FieldSet!) on FIELD_DEFINITION | ||
directive @key(fields: _FieldSet!) on OBJECT | INTERFACE | ||
directive @extends on OBJECT | INTERFACE | ||
`), | ||
], | ||
} | ||
: {})), (enableAWS | ||
? { | ||
schemas: [ | ||
graphql.buildSchema(/* GraphQL */ ` | ||
scalar AWSDate | ||
scalar AWSTime | ||
scalar AWSDateTime | ||
scalar AWSTimestamp | ||
scalar AWSEmail | ||
scalar AWSJSON | ||
scalar AWSURL | ||
scalar AWSPhone | ||
scalar AWSIPAddress | ||
scalar BigInt | ||
scalar Double | ||
directive @aws_subscribe( | ||
mutations: [String!]! | ||
) on FIELD_DEFINITION | ||
directive @deprecated( | ||
reason: String | ||
) on FIELD_DEFINITION | INPUT_FIELD_DEFINITION | ENUM | ENUM_VALUE | ||
directive @aws_auth( | ||
cognito_groups: [String!]! | ||
) on FIELD_DEFINITION | ||
directive @aws_api_key on FIELD_DEFINITION | OBJECT | ||
directive @aws_iam on FIELD_DEFINITION | OBJECT | ||
directive @aws_oidc on FIELD_DEFINITION | OBJECT | ||
directive @aws_cognito_user_pools( | ||
cognito_groups: [String!] | ||
) on FIELD_DEFINITION | OBJECT | ||
`), | ||
], | ||
} | ||
: {})))); | ||
} | ||
loadDocuments(pointer, options = {}) { | ||
return load.loadDocuments(pointer, Object.assign({ loaders: this.loaders, assumeValid: true, assumeValidSDL: true }, options)); | ||
return enrichError(load.loadDocuments(pointer, Object.assign({ loaders: this.loaders }, options))); | ||
} | ||
@@ -33,3 +86,3 @@ } | ||
const loaders = new LoadersRegistry(); | ||
config.loaders.forEach((loaderName) => loaders.register(loaderName)); | ||
config.loaders.forEach((loaderName) => loaders.registerModule(loaderName)); | ||
return loaders; | ||
@@ -41,2 +94,14 @@ } | ||
} | ||
/** | ||
* Adds `(source: <file-path>)` suffix to error message if source is available | ||
*/ | ||
function enrichError(looksPromising) { | ||
return looksPromising.catch((error) => { | ||
var _a, _b; | ||
if ((_a = error.source) === null || _a === void 0 ? void 0 : _a.name) { | ||
error.message = `${error.message} (source: ${(_b = error.source) === null || _b === void 0 ? void 0 : _b.name})`; | ||
} | ||
return Promise.reject(error); | ||
}); | ||
} | ||
@@ -43,0 +108,0 @@ exports.LoadersRegistry = LoadersRegistry; |
import { InspectorConfig } from '@graphql-inspector/config'; | ||
import { Source, SchemaPointerSingle } from '@graphql-tools/utils'; | ||
import { Source, UniversalLoader, SchemaPointerSingle } from '@graphql-tools/utils'; | ||
import { LoadSchemaOptions, LoadTypedefsOptions } from '@graphql-tools/load'; | ||
@@ -7,4 +7,5 @@ import { GraphQLSchema } from 'graphql'; | ||
private loaders; | ||
register(loaderName: string): void; | ||
loadSchema(pointer: SchemaPointerSingle, options?: Omit<LoadSchemaOptions, 'loaders'>): Promise<GraphQLSchema>; | ||
register(loader: UniversalLoader): void; | ||
registerModule(loaderName: string): void; | ||
loadSchema(pointer: SchemaPointerSingle, options: Omit<LoadSchemaOptions, "loaders"> | undefined, enableApolloFederation: boolean, enableAWS: boolean): Promise<GraphQLSchema>; | ||
loadDocuments(pointer: SchemaPointerSingle, options?: Omit<LoadTypedefsOptions, 'loaders'>): Promise<Source[]>; | ||
@@ -11,0 +12,0 @@ } |
import { loadSchema, loadDocuments } from '@graphql-tools/load'; | ||
import { buildSchema } from 'graphql'; | ||
@@ -7,6 +8,9 @@ class LoadersRegistry { | ||
} | ||
register(loaderName) { | ||
register(loader) { | ||
this.loaders.push(loader); | ||
} | ||
registerModule(loaderName) { | ||
try { | ||
const loader = loadModule(`@graphql-inspector/${loaderName}-loader`); | ||
this.loaders.push(loader); | ||
this.register(loader); | ||
} | ||
@@ -18,7 +22,56 @@ catch (error) { | ||
} | ||
loadSchema(pointer, options = {}) { | ||
return loadSchema(pointer, Object.assign({ loaders: this.loaders, assumeValid: true, assumeValidSDL: true }, options)); | ||
loadSchema(pointer, options = {}, enableApolloFederation, enableAWS) { | ||
return enrichError(loadSchema(pointer, Object.assign(Object.assign(Object.assign({ loaders: this.loaders }, options), (enableApolloFederation | ||
? { | ||
schemas: [ | ||
buildSchema(/* GraphQL */ ` | ||
scalar _FieldSet | ||
directive @external on FIELD_DEFINITION | ||
directive @requires(fields: _FieldSet!) on FIELD_DEFINITION | ||
directive @provides(fields: _FieldSet!) on FIELD_DEFINITION | ||
directive @key(fields: _FieldSet!) on OBJECT | INTERFACE | ||
directive @extends on OBJECT | INTERFACE | ||
`), | ||
], | ||
} | ||
: {})), (enableAWS | ||
? { | ||
schemas: [ | ||
buildSchema(/* GraphQL */ ` | ||
scalar AWSDate | ||
scalar AWSTime | ||
scalar AWSDateTime | ||
scalar AWSTimestamp | ||
scalar AWSEmail | ||
scalar AWSJSON | ||
scalar AWSURL | ||
scalar AWSPhone | ||
scalar AWSIPAddress | ||
scalar BigInt | ||
scalar Double | ||
directive @aws_subscribe( | ||
mutations: [String!]! | ||
) on FIELD_DEFINITION | ||
directive @deprecated( | ||
reason: String | ||
) on FIELD_DEFINITION | INPUT_FIELD_DEFINITION | ENUM | ENUM_VALUE | ||
directive @aws_auth( | ||
cognito_groups: [String!]! | ||
) on FIELD_DEFINITION | ||
directive @aws_api_key on FIELD_DEFINITION | OBJECT | ||
directive @aws_iam on FIELD_DEFINITION | OBJECT | ||
directive @aws_oidc on FIELD_DEFINITION | OBJECT | ||
directive @aws_cognito_user_pools( | ||
cognito_groups: [String!] | ||
) on FIELD_DEFINITION | OBJECT | ||
`), | ||
], | ||
} | ||
: {})))); | ||
} | ||
loadDocuments(pointer, options = {}) { | ||
return loadDocuments(pointer, Object.assign({ loaders: this.loaders, assumeValid: true, assumeValidSDL: true }, options)); | ||
return enrichError(loadDocuments(pointer, Object.assign({ loaders: this.loaders }, options))); | ||
} | ||
@@ -28,3 +81,3 @@ } | ||
const loaders = new LoadersRegistry(); | ||
config.loaders.forEach((loaderName) => loaders.register(loaderName)); | ||
config.loaders.forEach((loaderName) => loaders.registerModule(loaderName)); | ||
return loaders; | ||
@@ -36,4 +89,16 @@ } | ||
} | ||
/** | ||
* Adds `(source: <file-path>)` suffix to error message if source is available | ||
*/ | ||
function enrichError(looksPromising) { | ||
return looksPromising.catch((error) => { | ||
var _a, _b; | ||
if ((_a = error.source) === null || _a === void 0 ? void 0 : _a.name) { | ||
error.message = `${error.message} (source: ${(_b = error.source) === null || _b === void 0 ? void 0 : _b.name})`; | ||
} | ||
return Promise.reject(error); | ||
}); | ||
} | ||
export { LoadersRegistry, useLoaders }; | ||
//# sourceMappingURL=index.esm.js.map |
{ | ||
"name": "@graphql-inspector/loaders", | ||
"version": "0.0.0-canary.8127707", | ||
"version": "0.0.0-canary.02a53c5", | ||
"description": "Loaders in GraphQL Inspector", | ||
"sideEffects": false, | ||
"peerDependencies": { | ||
"@graphql-inspector/config": "0.0.0-canary.8127707", | ||
"@graphql-tools/utils": "^6.0.0", | ||
"@graphql-inspector/config": "0.0.0-canary.02a53c5", | ||
"@graphql-tools/utils": "^6.0.0 || ^7.0.0", | ||
"graphql": "^0.13.0 || ^14.0.0 || ^15.0.0" | ||
@@ -10,0 +10,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
21608
206