-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add virtual module for complete schema
- Loading branch information
1 parent
e956ca3
commit a15558f
Showing
8 changed files
with
168 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
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,6 @@ | ||
import { schema } from '#graphql/schema' | ||
|
||
// API endpoint that exposes the schema as JSON. | ||
// In production, use introspection instead! | ||
// This is here as demonstration and to easily test HMR. | ||
export default defineEventHandler(() => schema) |
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,9 @@ | ||
type Book { | ||
title: String | ||
author: Author | ||
} | ||
|
||
type Author { | ||
name: String | ||
books: [Book] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,31 @@ | ||
import { GraphQLFileLoader } from '@graphql-tools/graphql-file-loader' | ||
import { loadSchema as loadGraphqlSchema } from '@graphql-tools/load' | ||
import { GraphQLSchema, printSchema } from 'graphql' | ||
|
||
/** | ||
* Loads the schema from the GraphQL files. | ||
* @returns the GraphQL schema | ||
*/ | ||
export async function loadSchemaFromFiles( | ||
schemaPointers: string | string[], | ||
cwd?: string | ||
): Promise<GraphQLSchema> { | ||
return await loadGraphqlSchema(schemaPointers, { | ||
cwd, | ||
loaders: [new GraphQLFileLoader()], | ||
}) | ||
} | ||
|
||
export async function createSchemaImport( | ||
schemaPointers: string | string[], | ||
cwd?: string | ||
): Promise<string> { | ||
const schema = await loadSchemaFromFiles(schemaPointers, cwd) | ||
return ` | ||
import { loadSchemaSync } from '@graphql-tools/load' | ||
import { GraphQLFileLoader } from '@graphql-tools/graphql-file-loader' | ||
export const schema = loadSchemaSync(\`${printSchema(schema)}\`, { | ||
loaders: [new GraphQLFileLoader()] | ||
}) | ||
` | ||
} |