Typescript 找不到';合并graphql模式';打字稿
除非删除noImplicitAny,否则无法编译typescript 我得到了这个错误,我正在使用npm中的合并graphql模式库Typescript 找不到';合并graphql模式';打字稿,typescript,graphql,Typescript,Graphql,除非删除noImplicitAny,否则无法编译typescript 我得到了这个错误,我正在使用npm中的合并graphql模式库 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/vo
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
声明模块“合并graphql模式”
我的配置是这样的
{
"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"]
}
我应该具体做点什么吗?
我将lib从npm更改为schemaglue,即使它也没有类型,所以我做了同样的事情,但schemaglue也会出现同样的错误。
也许我在tsconfig中遗漏了什么
这就是我使用合并模式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 graphql ts服务器样板提供我也遇到了同样的问题!
我搬家把它修好了
import { fileLoader, mergeTypes, mergeResolvers } from 'merge-graphql-schemas'
追求
import { graphqlExpress, graphiqlExpress } from 'apollo-server-express'
import { makeExecutableSchema } from 'graphql-tools'
我不完全清楚为什么会发生这种情况,但我相信这是由于一些不可靠的依赖关系造成的。问题在于:
为了简单起见,您可以创建一个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;
}