@@ -4,12 +4,14 @@ import {
44 buildClientSchema ,
55 Source ,
66 buildSchema ,
7- printSchema
7+ printSchema ,
8+ parse
89} from "graphql" ;
910import { readFileSync } from "fs" ;
1011import { extname , resolve } from "path" ;
1112import { GraphQLSchemaProvider , SchemaChangeUnsubscribeHandler } from "./base" ;
1213import { NotificationHandler } from "vscode-languageserver" ;
14+ import { buildSchemaFromSDL } from "apollo-graphql" ;
1315
1416export interface FileSchemaProviderConfig {
1517 path ?: string ;
@@ -26,27 +28,27 @@ export class FileSchemaProvider implements GraphQLSchemaProvider {
2628 const { path, paths } = this . config ;
2729
2830 // load each path and get sdl string from each, if a list, concatenate them all
29- const sdlResults = path
30- ? this . loadFileAndGetSDL ( path )
31+ const documents = path
32+ ? [ this . loadFileAndGetDocument ( path ) ]
3133 : paths
32- ? paths . map ( this . loadFileAndGetSDL ) . join ( "\n" )
34+ ? paths . map ( this . loadFileAndGetDocument )
3335 : undefined ;
3436
35- if ( ! sdlResults )
37+ if ( ! documents )
3638 throw new Error (
3739 `Schema could not be loaded for [${
3840 path ? path : paths ? paths . join ( ", " ) : "undefined"
3941 } ]`
4042 ) ;
4143
42- this . schema = buildSchema ( sdlResults ) ;
44+ this . schema = buildSchemaFromSDL ( documents ) ;
4345
4446 if ( ! this . schema ) throw new Error ( `Schema could not be loaded for ${ path } ` ) ;
4547 return this . schema ;
4648 }
4749
48- // load a graphql file or introspection result and return the SDL version
49- loadFileAndGetSDL ( path : string ) {
50+ // load a graphql file or introspection result and return the GraphQL DocumentNode
51+ loadFileAndGetDocument ( path : string ) {
5052 let result ;
5153 try {
5254 result = readFileSync ( path , {
@@ -68,9 +70,9 @@ export class FileSchemaProvider implements GraphQLSchemaProvider {
6870 : parsed ;
6971
7072 const schema = buildClientSchema ( { __schema } ) ;
71- return printSchema ( schema ) ;
73+ return parse ( printSchema ( schema ) ) ;
7274 } else if ( ext === ".graphql" || ext === ".graphqls" || ext === ".gql" ) {
73- return result ;
75+ return parse ( result ) ;
7476 }
7577 throw new Error (
7678 "File Type not supported for schema loading. Must be a .json, .graphql, .gql, or .graphqls file"
0 commit comments