找不到'merge-graphql-schemas'TYPESCRIPT的声明文件

时间:2018-06-30 10:08:47

标签: typescript graphql

除非删除noImplicitAny,否则我将无法编译打字稿

我收到此错误,我正在使用npm中的merge-graphql-schemas库

    TSError: ⨯ Unable to compile TypeScript:
src/utils/genSchema.ts(1,44): error TS7016: Could not find a declaration file for module 'merge-graphql-schemas'. '/home/user/Documents/voting/node_modules/merge-graphql-schemas/dist/index.cjs.js' implicitly has an 'any' type.
  Try `npm install @types/merge-graphql-schemas` if it exists or add a new declaration (.d.ts) file containing `declare module 'merge-graphql-schemas';

在我的 src-> types-> merge-graphql-schemas.d.ts

声明模块“ merge-graphql-schemas”;

我的tsconfig就是这样

    {
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "lib": ["dom", "es6", "es2017", "esnext.asynciterable"],
    "sourceMap": true,
    "outDir": "./dist",
    "moduleResolution": "node",

    "removeComments": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "noImplicitThis": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "allowSyntheticDefaultImports": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true
  },
  "exclude": ["node_modules"],
  "include": ["./src/**/*.tsx", "./src/**/*.ts"]
}

我应该专门做什么吗? 我将库从npm更改为schemaglue,即使它也没有类型,所以我做了同样的事情,但对schemaglue我仍然遇到相同的错误。 也许我在tsconfig中缺少了什么?

这就是为什么我使用merge-schema-graphql

    import { mergeTypes, mergeResolvers } from "merge-graphql-schemas";
import * as path from "path";
import * as fs from "fs";
import { makeExecutableSchema } from "graphql-tools";
import * as glob from "glob";

export const genSchema = () => {
  const pathToModules = path.join(__dirname, "../modules");
  const graphqlTypes = glob
    .sync(`${pathToModules}/**/*.graphql`)
    .map(x => fs.readFileSync(x, { encoding: "utf8" }));

  const resolvers = glob
    .sync(`${pathToModules}/**/resolvers.?s`)
    .map(resolver => require(resolver).resolvers);

  return makeExecutableSchema({
    typeDefs: mergeTypes(graphqlTypes),
    resolvers: mergeResolvers(resolvers)
  });
};

Youtube Benawad提供的图片ql-ts-server-boilerplate

2 个答案:

答案 0 :(得分:0)

我遇到了同样的问题! 我通过移动来固定了

@client.command(pass_context=True,description="Linusifies a role")
@has_permissions(administrator = True)
async def rgb(ctx, role : discord.Role):
    if role in rgb_list:
        msg = "{}'s rgb is turned off :disappointed_relieved:".format(role)
        rgb_list.remove(role)
        await client.send_message(ctx.message.channel, msg)
    else:
        msg = "{}'s rgb has been turned on :christmas_tree:".format(role)
        rgb_list.append(role)
        await client.send_message(ctx.message.channel, msg)

到之后

import { fileLoader, mergeTypes, mergeResolvers } from 'merge-graphql-schemas'

我不确定为什么会发生这种情况,但我相信这是由于某些不可思议的依赖性所致。

答案 1 :(得分:0)

问题出在这里:https://github.com/okgrow/merge-graphql-schemas/issues/154

为简单起见,您可以创建一个global.d.ts文件并放置以下声明:

declare module 'merge-graphql-schemas' {
  export function fileLoader(...args: any[]): any;
  export function mergeResolvers(...args: any[]): any;
  export function mergeTypes(...args: any[]): any;
}