-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ability to rename root types (#976)
Closes #867
- Loading branch information
Showing
3 changed files
with
166 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`builder can replace the Mutation root type with an alternate type 1`] = ` | ||
"schema { | ||
query: Query | ||
mutation: RootMutation | ||
} | ||
type Mutation { | ||
ok: String | ||
} | ||
type Query { | ||
ok: Boolean! | ||
} | ||
type RootMutation { | ||
name: String | ||
} | ||
" | ||
`; | ||
|
||
exports[`builder can replace the Query root type with an alternate type 1`] = ` | ||
"schema { | ||
query: RootQuery | ||
} | ||
type Query { | ||
ok: String | ||
} | ||
type RootQuery { | ||
name: String | ||
} | ||
" | ||
`; | ||
|
||
exports[`builder can replace the Subscription root type with an alternate type 1`] = ` | ||
"schema { | ||
query: Query | ||
subscription: RootSubscription | ||
} | ||
type Query { | ||
ok: Boolean! | ||
} | ||
type RootSubscription { | ||
name: String | ||
} | ||
type Subscription { | ||
ok: String | ||
} | ||
" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { lexicographicSortSchema, printSchema } from 'graphql' | ||
import { makeSchema, objectType } from '../src' | ||
|
||
describe('builder', () => { | ||
it('can replace the Query root type with an alternate type', () => { | ||
const OtherQuery = objectType({ | ||
name: 'RootQuery', | ||
definition(t) { | ||
t.string('name') | ||
}, | ||
}) | ||
|
||
const Query = objectType({ | ||
name: 'Query', | ||
definition(t) { | ||
t.string('ok') | ||
}, | ||
}) | ||
|
||
const schema = makeSchema({ | ||
types: [OtherQuery, Query], | ||
schemaRoots: { | ||
query: OtherQuery, | ||
}, | ||
}) | ||
expect(printSchema(lexicographicSortSchema(schema))).toMatchSnapshot() | ||
}) | ||
|
||
it('can replace the Mutation root type with an alternate type', () => { | ||
const OtherMutation = objectType({ | ||
name: 'RootMutation', | ||
definition(t) { | ||
t.string('name') | ||
}, | ||
}) | ||
|
||
const Mutation = objectType({ | ||
name: 'Mutation', | ||
definition(t) { | ||
t.string('ok') | ||
}, | ||
}) | ||
|
||
const schema = makeSchema({ | ||
types: [OtherMutation, Mutation], | ||
schemaRoots: { | ||
mutation: OtherMutation, | ||
}, | ||
}) | ||
expect(printSchema(lexicographicSortSchema(schema))).toMatchSnapshot() | ||
}) | ||
|
||
it('can replace the Subscription root type with an alternate type', () => { | ||
const OtherSubscription = objectType({ | ||
name: 'RootSubscription', | ||
definition(t) { | ||
t.string('name') | ||
}, | ||
}) | ||
|
||
const Subscription = objectType({ | ||
name: 'Subscription', | ||
definition(t) { | ||
t.string('ok') | ||
}, | ||
}) | ||
|
||
const schema = makeSchema({ | ||
types: [OtherSubscription, Subscription], | ||
schemaRoots: { | ||
subscription: OtherSubscription, | ||
}, | ||
}) | ||
expect(printSchema(lexicographicSortSchema(schema))).toMatchSnapshot() | ||
}) | ||
}) |