Skip to content

Commit

Permalink
fix: exclude root types from wildcard import
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed May 22, 2018
1 parent fc9a12c commit 5739a25
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 82 deletions.
33 changes: 13 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,33 @@
},
"license": "MIT",
"repository": "git@github.com:graphcool/graphql-import.git",
"files": [
"dist"
],
"files": ["dist"],
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"typescript": {
"definition": "dist/index.d.ts"
},
"nyc": {
"extension": [
".ts"
],
"require": [
"ts-node/register"
],
"include": [
"src/**/*.ts"
],
"exclude": [
"**/*.d.ts",
"**/*.test.ts"
],
"extension": [".ts"],
"require": ["ts-node/register"],
"include": ["src/**/*.ts"],
"exclude": ["**/*.d.ts", "**/*.test.ts"],
"all": true,
"sourceMap": true,
"instrument": true
},
"scripts": {
"prepare": "npm run build",
"build": "rm -rf dist && tsc -d",
"testlocal": "npm run build && nyc --reporter lcov --reporter text ava-ts --verbose src/**/*.test.ts",
"test-only": "npm run build && nyc --reporter lcov ava-ts --verbose src/**/*.test.ts --tap | tap-xunit > ~/reports/ava.xml",
"testlocal":
"npm run build && nyc --reporter lcov --reporter text ava-ts -u --verbose src/**/*.test.ts",
"test-only":
"npm run build && mkdir -p ~/reports && nyc --reporter lcov ava-ts --verbose src/**/*.test.ts --tap | tap-xunit > ~/reports/ava.xml",
"test": "tslint src/**/*.ts && npm run test-only",
"docs": "typedoc --out docs src/index.ts --hideGenerator --exclude **/*.test.ts",
"docs:publish": "cp ./now.json ./docs && cd docs && now --public -f && now alias && now rm --yes --safe graphql-import & cd .."
"docs":
"typedoc --out docs src/index.ts --hideGenerator --exclude **/*.test.ts",
"docs:publish":
"cp ./now.json ./docs && cd docs && now --public -f && now alias && now rm --yes --safe graphql-import & cd .."
},
"peerDependencies": {
"graphql": "^0.11.0 || ^0.12.0 || ^0.13.0"
Expand Down
97 changes: 71 additions & 26 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ test('importSchema: import all from objects', t => {
}`

const schemas = {
schemaA, schemaB, schemaC
schemaA,
schemaB,
schemaC,
}

const expectedSDL = `\
Expand Down Expand Up @@ -246,7 +248,7 @@ test(`importSchema: import all mix 'n match`, t => {
}`

const schemas = {
schemaB
schemaB,
}

const expectedSDL = `\
Expand Down Expand Up @@ -274,7 +276,6 @@ type C2 {
})

test(`importSchema: import all mix 'n match 2`, t => {

const schemaA = `
# import * from "fixtures/import-all/b.graphql"
Expand Down Expand Up @@ -360,7 +361,9 @@ test(`importSchema: import all - exclude Query/Mutation/Subscription type`, t =>
}`

const schemas = {
schemaA, schemaB, schemaC
schemaA,
schemaB,
schemaC,
}

const expectedSDL = `\
Expand Down Expand Up @@ -499,7 +502,10 @@ type B2 implements B {
id: ID!
}
`
t.is(importSchema('fixtures/interfaces-implements-many/a.graphql'), expectedSDL)
t.is(
importSchema('fixtures/interfaces-implements-many/a.graphql'),
expectedSDL,
)
})

test('importSchema: input types', t => {
Expand Down Expand Up @@ -602,14 +608,14 @@ interface Node {

test('root field imports', t => {
const expectedSDL = `\
type Dummy {
field: String
}
type Query {
posts(filter: PostFilter): [Post]
}
type Dummy {
field: String
}
type Post {
field1: String
}
Expand All @@ -624,16 +630,16 @@ input PostFilter {

test('merged root field imports', t => {
const expectedSDL = `\
type Dummy {
field: String
}
type Query {
helloA: String
posts(filter: PostFilter): [Post]
hello: String
}
type Dummy {
field: String
}
type Post {
field1: String
}
Expand Down Expand Up @@ -666,36 +672,75 @@ type Shared {
})

test('missing type on type', t => {
const err = t.throws(() => importSchema('fixtures/type-not-found/a.graphql'), Error)
t.is(err.message, `Field test: Couldn't find type Post in any of the schemas.`)
const err = t.throws(
() => importSchema('fixtures/type-not-found/a.graphql'),
Error,
)
t.is(
err.message,
`Field test: Couldn't find type Post in any of the schemas.`,
)
})

test('missing type on interface', t => {
const err = t.throws(() => importSchema('fixtures/type-not-found/b.graphql'), Error)
t.is(err.message, `Field test: Couldn't find type Post in any of the schemas.`)
const err = t.throws(
() => importSchema('fixtures/type-not-found/b.graphql'),
Error,
)
t.is(
err.message,
`Field test: Couldn't find type Post in any of the schemas.`,
)
})

test('missing type on input type', t => {
const err = t.throws(() => importSchema('fixtures/type-not-found/c.graphql'), Error)
t.is(err.message, `Field post: Couldn't find type Post in any of the schemas.`)
const err = t.throws(
() => importSchema('fixtures/type-not-found/c.graphql'),
Error,
)
t.is(
err.message,
`Field post: Couldn't find type Post in any of the schemas.`,
)
})

test('missing interface type', t => {
const err = t.throws(() => importSchema('fixtures/type-not-found/d.graphql'), Error)
t.is(err.message, `Couldn't find interface MyInterface in any of the schemas.`)
const err = t.throws(
() => importSchema('fixtures/type-not-found/d.graphql'),
Error,
)
t.is(
err.message,
`Couldn't find interface MyInterface in any of the schemas.`,
)
})

test('missing union type', t => {
const err = t.throws(() => importSchema('fixtures/type-not-found/e.graphql'), Error)
const err = t.throws(
() => importSchema('fixtures/type-not-found/e.graphql'),
Error,
)
t.is(err.message, `Couldn't find type C in any of the schemas.`)
})

test('missing type on input type', t => {
const err = t.throws(() => importSchema('fixtures/type-not-found/f.graphql'), Error)
t.is(err.message, `Field myfield: Couldn't find type Post in any of the schemas.`)
const err = t.throws(
() => importSchema('fixtures/type-not-found/f.graphql'),
Error,
)
t.is(
err.message,
`Field myfield: Couldn't find type Post in any of the schemas.`,
)
})

test('missing type on directive', t => {
const err = t.throws(() => importSchema('fixtures/type-not-found/g.graphql'), Error)
t.is(err.message, `Directive first: Couldn't find type first in any of the schemas.`)
const err = t.throws(
() => importSchema('fixtures/type-not-found/g.graphql'),
Error,
)
t.is(
err.message,
`Directive first: Couldn't find type first in any of the schemas.`,
)
})
Loading

0 comments on commit 5739a25

Please sign in to comment.