未知类型查询(GraphQL)

时间:2020-07-16 05:04:18

标签: graphql

我使用翻译器是因为我不会英语。

我正在学习graphql和网络。

这本书没有任何错误,但是当我尝试时,出现了错误。

我不知道这意味着什么。 我需要你的帮助。

我的git链接https://github.com/kimud7/Graphql

Error: Unknown type "Query".
    at assertValidSDL (/Users/kud/node-coder/test/node_modules/graphql/validation/validate.js:108:11)
    at Object.buildASTSchema (/Users/kud/node-coder/test/node_modules/graphql/utilities/buildASTSchema.js:71:34)
    at buildSchemaFromTypeDefinitions (/Users/kud/node-coder/test/dist/schema/src/buildSchemaFromTypeDefinitions.js:8:18)
    at Object.makeExecutableSchema (/Users/kud/node-coder/test/dist/schema/src/makeExecutableSchema.js:64:18)
    at Object.<anonymous> (/Users/kud/node-coder/test/src/schema.ts:17:17)
    at Module._compile (internal/modules/cjs/loader.js:1201:30)
    at Module.m._compile (/Users/kud/node-coder/test/node_modules/ts-node/src/index.ts:858:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:1221:10)
    at Object.require.extensions.<computed> [as .ts] (/Users/kud/node-coder/test/node_modules/ts-node/src/index.ts:861:12)
    at Module.load (internal/modules/cjs/loader.js:1050:32)

说hello.ts

const resolvers = {
    Query : {
        sayHello: () =>`hey hello how are you`
    }
};
export default resolvers;

说hello.graphql

type Query{
    sayBye:string!
}

schema.ts

import { GraphQLSchema } from "graphql";
import { makeExecutableSchema } from "graphql-tools";
import { fileLoader, mergeResolvers, mergeTypes } from "merge-graphql-schemas";
import path from "path";

 const allTypes: GraphQLSchema[] = fileLoader(
   path.join(__dirname, "./api/**/*.graphql")
 );

 const allResolvers: any[] = fileLoader(
   path.join(__dirname, "./api/**/*.resolvers.*")
 );

 const mergedTypes = mergeTypes(allTypes);
 const mergedResolvers = mergeResolvers(allResolvers);

 const schema = makeExecutableSchema({
   typeDefs: mergedTypes,
   resolvers: mergedResolvers
 });

 export default schema;

App.ts

import cors from "cors";
 import { GraphQLServer } from "graphql-yoga";
 import helmet from "helmet";
 import logger from "morgan";
 import schema from "./schema";

 class App {
   public app: GraphQLServer;
   constructor() {
     this.app = new GraphQLServer({
         schema
     });
     this.middlewares();
   }
   private middlewares = (): void => {
    this.app.express.use(cors());
    this.app.express.use(logger("dev"));
    this.app.express.use(helmet());
  };
}
export default new App().app;

0 个答案:

没有答案