我正在使用Apollo Server上使用GraphQL上的Nestjs实施一个框架,我想使用一些自定义的GraphQl标量。我找到了这个网站,,这有助于导入自定义标量,而无需实际实现 https://docs.nestjs.com/graphql/scalars#create-a-custom-scalar 。要具体来说,我想使用 bigint
, time
和 url
。
从,我不确定代码在哪里。我应该在 app.module.ts
上对此进行编码?
// or import specific typeDefs only with ES6 Import
import { ScalarNameTypeDefinition } from 'graphql-scalars';
// or import specific typeDefs only with CommonJS
const { ScalarNameTypeDefinition } = require('graphql-scalars');
// or import all typeDefs once with ES6 Import
import { typeDefs as scalarTypeDefs } from 'graphql-scalars';
// or import all typeDefs once with CommonJS
const { typeDefs: scalarTypeDefs } = require('graphql-scalars');
const typeDefs = [
...scalarTypeDefs,
// other typeDefs
];
// or
const typeDefs = [
ScalarNameTypeDefinition,
// other typeDefs
];
我当前的graphQlModule:
GraphQLModule.forRoot<ApolloDriverConfig>({
driver: ApolloDriver,
typePaths: ['./**/**/**/*.graphql'],
definitions: {
path: join(process.cwd(), 'src/graphql.ts'),
outputAs: 'class',
},
}),
?代码应该在哪里? Assets.Resolver.ts
?我也不明白此代码属于?
简而言之,如何在Apollo服务器上的Nestjs框架中使用 GraphQl-Scalars
软件包?是否有开源的GitHub存储库可以研究?
I am implementing a framework using Nestjs on Apollo Server using GraphQL and I would like to use some custom GraphQL scalars. I found this site, https://www.graphql-scalars.dev/docs/quick-start, which is helpful for importing custom scalars without actually implementing them as written on https://docs.nestjs.com/graphql/scalars#create-a-custom-scalar. To be specific, I would like to use BigInt
, Time
, and URL
.
From the docs on the quick start page, I am uncertain where the code belongs at. Should I code this at app.module.ts
?
// or import specific typeDefs only with ES6 Import
import { ScalarNameTypeDefinition } from 'graphql-scalars';
// or import specific typeDefs only with CommonJS
const { ScalarNameTypeDefinition } = require('graphql-scalars');
// or import all typeDefs once with ES6 Import
import { typeDefs as scalarTypeDefs } from 'graphql-scalars';
// or import all typeDefs once with CommonJS
const { typeDefs: scalarTypeDefs } = require('graphql-scalars');
const typeDefs = [
...scalarTypeDefs,
// other typeDefs
];
// or
const typeDefs = [
ScalarNameTypeDefinition,
// other typeDefs
];
my current GraphQLModule:
GraphQLModule.forRoot<ApolloDriverConfig>({
driver: ApolloDriver,
typePaths: ['./**/**/**/*.graphql'],
definitions: {
path: join(process.cwd(), 'src/graphql.ts'),
outputAs: 'class',
},
}),
How about the resolver map? Where should the code belong at? assets.resolver.ts
? I also don't understand where this code belongs to?
In short, how to use graphql-scalars
package in the Nestjs framework on Apollo Server? Is there any open-source GitHub repository to look into?
发布评论
评论(1)
在这里看看 nestjs导入自定义标量
我的app.module.ts外观:
在我的.graphql文件中,我可以使用这些类型:
完成此操作后,我可以使用这些新标量在GraphQl Playground上成功运行查询。
您甚至不需要创建自己的自定义标量。您只能导入所需的三个,就可以了。
Have a look here NestJs Import a custom scalar
This is how my app.module.ts looks:
In my .graphql file I can then use those types:
After I did this I could successfully run queries on the GraphQL Playground using those new scalars.
You don't even need to create your own custom scalar. You can just import the three that you need and you are good to go.