Skip to content

Commit

Permalink
enhance(loaders): remove optional methods from the Loader interface
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Jul 14, 2021
1 parent 7d962a5 commit 9c26b84
Show file tree
Hide file tree
Showing 16 changed files with 19 additions and 77 deletions.
5 changes: 5 additions & 0 deletions .changeset/cool-onions-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-tools/utils': minor
---

enhance(loaders): remove optional methods from the Loader interface
4 changes: 0 additions & 4 deletions packages/loaders/apollo-engine/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ const DEFAULT_APOLLO_ENDPOINT = 'https://engine-graphql.apollographql.com/api/gr
* This loader loads a schema from Apollo Engine
*/
export class ApolloEngineLoader implements Loader<ApolloEngineOptions> {
loaderId() {

This comment has been minimized.

Copy link
@dylanwatsonsoftware

dylanwatsonsoftware Jul 28, 2021

@ardatan Looks like this is causing issues. When I run graphql-codegen now, with this version of prisma-loader, I am getting loader.loaderId is not a function. I.. don't think this is meant to be optional. Certainly @graphql-codegen/cli doesn't treat it as such.

This comment has been minimized.

Copy link
@kevinalh

kevinalh Sep 26, 2021

same issue with graphql-cli Urigo/graphql-cli#1807

return 'apollo-engine';
}

private getFetchArgs(options: ApolloEngineOptions): [string, RequestInit] {
return [
options.engine.endpoint || DEFAULT_APOLLO_ENDPOINT,
Expand Down
4 changes: 0 additions & 4 deletions packages/loaders/code-file/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ export class CodeFileLoader implements Loader<CodeFileLoaderOptions> {
return { ...this.config, ...options };
}

loaderId(): string {
return 'code-file';
}

async canLoad(pointer: string, options: CodeFileLoaderOptions): Promise<boolean> {
options = this.getMergedOptions(options);

Expand Down
4 changes: 0 additions & 4 deletions packages/loaders/git/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ export type GitLoaderOptions = BaseLoaderOptions & {
* ```
*/
export class GitLoader implements Loader<GitLoaderOptions> {
loaderId() {
return 'git-loader';
}

async canLoad(pointer: string) {
return this.canLoadSync(pointer);
}
Expand Down
6 changes: 0 additions & 6 deletions packages/loaders/git/tests/loader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ describe('GitLoader', () => {
return `git:${lastCommit}:packages/loaders/git/tests/test-files/${fileName}`;
};

describe('loaderId', () => {
it('should return a loader id', () => {
expect(loader.loaderId()).toBeDefined();
});
});

describe('canLoad', () => {
runTests({
async: loader.canLoad.bind(loader),
Expand Down
4 changes: 0 additions & 4 deletions packages/loaders/github/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ export interface GithubLoaderOptions extends BaseLoaderOptions {
* ```
*/
export class GithubLoader implements Loader<GithubLoaderOptions> {
loaderId() {
return 'github-loader';
}

async canLoad(pointer: string) {
return typeof pointer === 'string' && pointer.toLowerCase().startsWith('github:');
}
Expand Down
4 changes: 0 additions & 4 deletions packages/loaders/graphql-file/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ function createGlobbyOptions(options: GraphQLFileLoaderOptions): GlobbyOptions {
* ```
*/
export class GraphQLFileLoader implements Loader<GraphQLFileLoaderOptions> {
loaderId(): string {
return 'graphql-file';
}

async canLoad(pointer: string, options: GraphQLFileLoaderOptions): Promise<boolean> {
if (isValidPath(pointer)) {
if (FILE_EXTENSIONS.find(extension => pointer.endsWith(extension))) {
Expand Down
6 changes: 0 additions & 6 deletions packages/loaders/graphql-file/tests/loader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ describe('GraphQLFileLoader', () => {
return join('packages/loaders/graphql-file/tests/test-files', fileName);
};

describe('loaderId', () => {
it('should return a loader id', () => {
expect(loader.loaderId()).toBeDefined();
});
});

describe('canLoad', () => {
runTests({
async: loader.canLoad.bind(loader),
Expand Down
4 changes: 0 additions & 4 deletions packages/loaders/json-file/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ export interface JsonFileLoaderOptions extends BaseLoaderOptions {}
* ```
*/
export class JsonFileLoader implements Loader {
loaderId(): string {
return 'json-file';
}

async canLoad(pointer: string, options: JsonFileLoaderOptions): Promise<boolean> {
if (isValidPath(pointer)) {
if (FILE_EXTENSIONS.find(extension => pointer.endsWith(extension))) {
Expand Down
6 changes: 0 additions & 6 deletions packages/loaders/json-file/tests/loader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ describe('JsonFileLoader', () => {
return join('packages/loaders/json-file/tests/test-files', fileName);
};

describe('loaderId', () => {
it('should return a loader id', () => {
expect(loader.loaderId()).toBeDefined();
});
});

describe('canLoad', () => {
runTests({
async: loader.canLoad.bind(loader),
Expand Down
4 changes: 0 additions & 4 deletions packages/loaders/module/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ function extractData(pointer: string): {
* ```
*/
export class ModuleLoader implements Loader {
loaderId() {
return 'module-loader';
}

private isExpressionValid(pointer: string) {
return typeof pointer === 'string' && pointer.toLowerCase().startsWith('module:');
}
Expand Down
6 changes: 0 additions & 6 deletions packages/loaders/module/tests/loader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ describe('ModuleLoader', () => {
return `module:${absolutePath}${exportName ? `#${exportName}` : ''}`;
};

describe('loaderId', () => {
it('should return a loader id', () => {
expect(loader.loaderId()).toBeDefined();
});
});

describe('canLoad', () => {
runTests({
async: loader.canLoad.bind(loader),
Expand Down
4 changes: 0 additions & 4 deletions packages/loaders/prisma/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ export interface PrismaLoaderOptions extends LoadFromUrlOptions {
* This loader loads a schema from a `prisma.yml` file
*/
export class PrismaLoader extends UrlLoader {
loaderId() {
return 'prisma';
}

canLoadSync() {
return false;
}
Expand Down
4 changes: 0 additions & 4 deletions packages/loaders/url/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,6 @@ const isCompatibleUri = (uri: string): boolean => {
* ```
*/
export class UrlLoader implements Loader<LoadFromUrlOptions> {
loaderId(): string {
return 'url';
}

async canLoad(pointer: string, options: LoadFromUrlOptions): Promise<boolean> {
return this.canLoadSync(pointer, options);
}
Expand Down
3 changes: 0 additions & 3 deletions packages/utils/src/loaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ export type WithList<T> = T | T[];
export type ElementOf<TList> = TList extends Array<infer TElement> ? TElement : never;

export interface Loader<TOptions extends BaseLoaderOptions = BaseLoaderOptions> {
loaderId(): string;
canLoad(pointer: string, options?: TOptions): Promise<boolean>;
canLoadSync?(pointer: string, options?: TOptions): boolean;
load(pointer: string, options?: TOptions): Promise<Source[] | null | never>;
loadSync?(pointer: string, options?: TOptions): Source[] | null | never;
}
28 changes: 14 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,21 @@
tslib "^1.10.0"
zen-observable "^0.8.14"

"@apollo/federation@0.25.2", "@apollo/federation@^0.25.2":
version "0.25.2"
resolved "https://registry.yarnpkg.com/@apollo/federation/-/federation-0.25.2.tgz#10b2e22ac20e64701fd6d31d9abbf7f411b03763"
integrity sha512-TrRCrGniHpnRwALm2J7q2c1X4Lcc95e7SeHkVjascaQx6nBZGFbBXadw8rOPxlw5syfxYf8h9winF+wwld+gsg==
"@apollo/federation@0.26.0", "@apollo/federation@^0.26.0":
version "0.26.0"
resolved "https://registry.yarnpkg.com/@apollo/federation/-/federation-0.26.0.tgz#72c89f01995bd2e066d447fed4aa58678d759bf6"
integrity sha512-j3l6lhQod630LQzLm2hhDyQQJtQikT7vRtRgIa3PuKEq6ouuOd1OQERhBnecobJlUfRWJkfvjYJ/PhQZ2sm/7Q==
dependencies:
apollo-graphql "^0.9.3"
lodash.xorby "^4.7.0"

"@apollo/gateway@0.32.0":
version "0.32.0"
resolved "https://registry.yarnpkg.com/@apollo/gateway/-/gateway-0.32.0.tgz#639b7b826c76a2bffdf777902010485dfd981918"
integrity sha512-Pxq3VVxG1ALrFNN8SM3RVy6Kwm+5p1KG3ObVmQX720Wx5WpRKvCRC23J/c3oFRpsGqjPOglh3vmpAQVdJJTCZA==
"@apollo/gateway@0.33.0":
version "0.33.0"
resolved "https://registry.yarnpkg.com/@apollo/gateway/-/gateway-0.33.0.tgz#6e282fb88eb86d9ab9ae35d6d5d3e174085a6907"
integrity sha512-NQTFysgRzPYR8g90K43/hgH+Rxe7F/E2G2Linfc81VVNk5NruRSUeQV0EnsROC7lLbCqiCJ+WSQcN0ZaR2Jo7A==
dependencies:
"@apollo/federation" "^0.25.2"
"@apollo/query-planner" "^0.2.2"
"@apollo/federation" "^0.26.0"
"@apollo/query-planner" "^0.2.3"
"@opentelemetry/api" "^1.0.1"
"@types/node-fetch" "2.5.10"
apollo-graphql "^0.9.3"
Expand Down Expand Up @@ -191,10 +191,10 @@
"@types/node" "^10.1.0"
long "^4.0.0"

"@apollo/query-planner@^0.2.2":
version "0.2.2"
resolved "https://registry.yarnpkg.com/@apollo/query-planner/-/query-planner-0.2.2.tgz#5397e5cd8a73dede34c485fb0c5fefa054f9153a"
integrity sha512-+RZSKY0xDYki9qwlzKXDNa+jrbj0Qstq44lcB21aViiDdEJWOTwf7Cqg3h/hN7QsUnL75XiDrwsjMLnwFdHSoQ==
"@apollo/query-planner@^0.2.3":
version "0.2.3"
resolved "https://registry.yarnpkg.com/@apollo/query-planner/-/query-planner-0.2.3.tgz#8018ae12c24541838541cc7b20d6a628556918e5"
integrity sha512-3jYHLhuUTolAouVTkR1NrGH7ZQzj91KfH1L1Ddd2i2hfCG6VDj9xuRe+nznYV1Sk3/Uy226d7BPKo110H/3Pow==
dependencies:
chalk "^4.1.0"
deep-equal "^2.0.5"
Expand Down

0 comments on commit 9c26b84

Please sign in to comment.