From 396562052de159f1052ac2d1c75e2a8880f7fa62 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Tue, 3 Sep 2019 15:12:57 +0200 Subject: [PATCH] fix(load): support graphqls and gqls extensions --- packages/load/__tests__/schema-from-github.ts | 2 +- packages/load/src/schema/from-git.ts | 8 ++------ packages/load/src/schema/from-github.ts | 6 ++++-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/load/__tests__/schema-from-github.ts b/packages/load/__tests__/schema-from-github.ts index e72695529a..1e491eaf91 100644 --- a/packages/load/__tests__/schema-from-github.ts +++ b/packages/load/__tests__/schema-from-github.ts @@ -8,7 +8,7 @@ const {Response} = jest.requireActual('node-fetch'); const owner = 'kamilkisiela'; const name = 'graphql-inspector-example'; const ref = 'master'; -const path = 'example/schemas/schema.graphql'; +const path = 'example/schemas/schema.graphqls'; const token = 'MY-SECRET-TOKEN'; const pointer = `github:${owner}/${name}#${ref}:${path}`; diff --git a/packages/load/src/schema/from-git.ts b/packages/load/src/schema/from-git.ts index c20135c2a3..ca255a56ed 100644 --- a/packages/load/src/schema/from-git.ts +++ b/packages/load/src/schema/from-git.ts @@ -42,16 +42,12 @@ export const fromGit: SchemaHandler = function fromGit(pointer) { throw new Error('Unable to load schema from git: ' + error); } - if (/\.(gql|graphql)$/i.test(path)) { + if (/\.(gql|graphql)s?$/i.test(path)) { return buildSchema(schemaString); } if (/\.json$/i.test(path)) { - try { - return buildClientSchema(JSON.parse(schemaString)); - } catch (error) { - throw new Error('unable to build schema from introspection result'); - } + return buildClientSchema(JSON.parse(schemaString)); } throw new Error('Unable to build schema from git'); diff --git a/packages/load/src/schema/from-github.ts b/packages/load/src/schema/from-github.ts index 2784b3e10a..b572b33cb3 100644 --- a/packages/load/src/schema/from-github.ts +++ b/packages/load/src/schema/from-github.ts @@ -83,9 +83,11 @@ export const fromGithub: SchemaHandler = function fromGithub( const text = response.data.repository.object.text; - if (/\.(gql|graphql)$/i.test(path)) { + if (/\.(gql|graphql)s?$/i.test(path)) { return buildSchema(text); - } else if (/\.json$/i.test(path)) { + } + + if (/\.json$/i.test(path)) { return buildClientSchema(JSON.parse(text)); }