|
| 1 | +import '../../../../testing/to-be-similar-string' |
| 2 | +import { loadSchema, loadSchemaSync } from '@graphql-tools/load'; |
| 3 | +import { printSchemaWithDirectives } from '@graphql-tools/utils'; |
| 4 | +import { runTests, useMonorepo } from '../../../../testing/utils'; |
| 5 | +import { printSchema } from 'graphql'; |
| 6 | + |
| 7 | +const monorepo = useMonorepo({ |
| 8 | + dirname: __dirname, |
| 9 | +}); |
| 10 | +describe('schema from string', () => { |
| 11 | + |
| 12 | + monorepo.correctCWD(); |
| 13 | + |
| 14 | + runTests({ |
| 15 | + async: loadSchema, |
| 16 | + sync: loadSchemaSync |
| 17 | + })(load => { |
| 18 | + it('should load schema from string', async () => { |
| 19 | + const schemaString = /* GraphQL */` |
| 20 | + type Query { |
| 21 | + book: String |
| 22 | + } |
| 23 | + `; |
| 24 | + const schema = await load(schemaString, { |
| 25 | + loaders: [] |
| 26 | + }); |
| 27 | + const printedSchema = printSchema(schema); |
| 28 | + expect(printedSchema).toBeSimilarString(schemaString); |
| 29 | + }); |
| 30 | + it('should load schema from string with schema definition', async () => { |
| 31 | + const schemaString = /* GraphQL */` |
| 32 | + schema { |
| 33 | + query: Query |
| 34 | + } |
| 35 | +
|
| 36 | + type Query { |
| 37 | + book: String |
| 38 | + } |
| 39 | + `; |
| 40 | + const schema = await load(schemaString, { |
| 41 | + loaders: [] |
| 42 | + }); |
| 43 | + const printedSchema = printSchemaWithDirectives(schema); |
| 44 | + expect(printedSchema).toBeSimilarString(schemaString); |
| 45 | + }); |
| 46 | + it('should load schema from string with schema definition and convertExtensions flag', async () => { |
| 47 | + const schemaString = /* GraphQL */` |
| 48 | + schema { |
| 49 | + query: Query |
| 50 | + } |
| 51 | +
|
| 52 | + type Query { |
| 53 | + book: String |
| 54 | + } |
| 55 | + `; |
| 56 | + const schema = await load(schemaString, { |
| 57 | + loaders: [], |
| 58 | + convertExtensions: true |
| 59 | + }); |
| 60 | + const printedSchema = printSchemaWithDirectives(schema); |
| 61 | + expect(printedSchema).toBeSimilarString(schemaString); |
| 62 | + }); |
| 63 | + }) |
| 64 | +}) |
0 commit comments