-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(generator): support any schema file name (#1143)
- Loading branch information
1 parent
670bb46
commit a940c49
Showing
8 changed files
with
169 additions
and
22 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,98 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`can introspect schema from url 1`] = ` | ||
"interface Being { | ||
id: Int | ||
name: String | ||
} | ||
input DateFilter { | ||
gte: Float | ||
lte: Float | ||
} | ||
type Mutation { | ||
addPokemon(attack: Int, defense: Int, hp: Int, name: String!, type: PokemonType!): Pokemon | ||
} | ||
type Patron implements Being { | ||
id: Int | ||
money: Int | ||
name: String | ||
} | ||
type Pokemon implements Being { | ||
attack: Int | ||
birthday: Int | ||
defense: Int | ||
hp: Int | ||
id: Int | ||
name: String | ||
trainer: Trainer | ||
type: PokemonType | ||
} | ||
input PokemonFilter { | ||
birthday: DateFilter | ||
name: StringFilter | ||
} | ||
enum PokemonType { | ||
electric | ||
fire | ||
grass | ||
water | ||
} | ||
type Query { | ||
beings: [Being!]! | ||
pokemon: [Pokemon!] | ||
pokemonByName(name: String!): [Pokemon!] | ||
pokemons(filter: PokemonFilter): [Pokemon!] | ||
trainerByName(name: String!): Trainer | ||
trainers: [Trainer!] | ||
} | ||
input StringFilter { | ||
contains: String | ||
in: [String!] | ||
} | ||
type Trainer implements Being { | ||
class: TrainerClass | ||
fans: [Patron!] | ||
id: Int | ||
name: String | ||
pokemon: [Pokemon!] | ||
} | ||
enum TrainerClass { | ||
bugCatcher | ||
camper | ||
picnicker | ||
psychic | ||
psychicMedium | ||
psychicYoungster | ||
sailor | ||
superNerd | ||
tamer | ||
teamRocketGrunt | ||
triathlete | ||
youngster | ||
youth | ||
}" | ||
`; | ||
exports[`can load schema from custom dir using default file name 1`] = ` | ||
"type Query { | ||
defaultNamedSchemaFile: Boolean | ||
} | ||
" | ||
`; | ||
exports[`can load schema from custom path 1`] = ` | ||
"type Query { | ||
customNamedSchemaFile: Boolean | ||
} | ||
" | ||
`; |
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,28 @@ | ||
import _ from 'json-bigint' | ||
import { expect } from 'vitest' | ||
import { test } from '../../../tests/_/helpers.js' | ||
import { createConfig } from './config.js' | ||
|
||
test(`can load schema from custom path`, async () => { | ||
const customPathFile = `./tests/_/fixtures/custom.graphql` | ||
const config = await createConfig({ sourceSchema: { type: `sdl`, dirOrFilePath: customPathFile } }) | ||
const field = config.schema.instance.getQueryType()?.getFields()[`customNamedSchemaFile`] | ||
expect(config.paths.project.inputs.schema).toEqual(customPathFile) | ||
expect(config.schema.sdl).toMatchSnapshot() | ||
expect(field).toBeDefined() | ||
}) | ||
|
||
test(`can load schema from custom dir using default file name`, async () => { | ||
const customPathDir = `tests/_/fixtures` | ||
const config = await createConfig({ sourceSchema: { type: `sdl`, dirOrFilePath: customPathDir } }) | ||
const field = config.schema.instance.getQueryType()?.getFields()[`defaultNamedSchemaFile`] | ||
expect(config.paths.project.inputs.schema).toEqual(customPathDir + `/schema.graphql`) | ||
expect(config.schema.sdl).toMatchSnapshot() | ||
expect(field).toBeDefined() | ||
}) | ||
|
||
test(`can introspect schema from url`, async ({ pokemonService }) => { | ||
const config = await createConfig({ sourceSchema: { type: `url`, url: pokemonService.url } }) | ||
expect(config.paths.project.inputs.schema).toEqual(null) | ||
expect(config.schema.sdl).toMatchSnapshot() | ||
}) |
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
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,3 @@ | ||
type Query { | ||
customNamedSchemaFile: Boolean | ||
} |
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,3 @@ | ||
type Query { | ||
defaultNamedSchemaFile: Boolean | ||
} |
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