GraphQL中与TypeScript中的{[key:string]:string}等价



TypeScript中GraphQL中GraphQL{ [key: string]: string }的等价性是什么?

#schema.gql
type App implements Node {
name: String!
tags: 'EQUIVALENCE { [key: string]: string }'
}

谢谢!

GraphQL中不鼓励使用原始JSON(这就是tags字段的样子(,请参阅以下讨论:https://github.com/graphql/graphql-spec/issues/612

但是,有一种方法可以使用自定义标量(https://www.graphql-tools.com/docs/scalars)并将CCD_ 3键入为CCD_。请参见此处:https://www.graphql-tools.com/docs/scalars#using-a包

我在这里复制这个例子,供后人使用

import { makeExecutableSchema } from '@graphql-tools/schema'
import { GraphQLJSON } from 'graphql-scalars'
const schemaString = `
scalar JSON
type Foo {
tags: JSON
}
type Query {
foo: Foo
}
`
const resolveFunctions = {
JSON: GraphQLJSON
}
const jsSchema = makeExecutableSchema({ typeDefs: schemaString, resolvers: resolveFunctions })

如果可以的话,我建议你选择这样的东西:

#schema.gql
type App implements Node {
name: String!
tags: [ { name: String!, value: String! }! ]!
}

最新更新