What is the equivalence in GraphQL { [key: string]: string } in GraphQL in TypeScript?
#schema.gql
type App implements Node {
name: String!
tags: 'EQUIVALENCE { [key: string]: string }'
}
Thanks!
Raw JSON is discouraged in GraphQL (which is what your tags field looks like), see this discussion: https://github.com/graphql/graphql-spec/issues/612
But, there is a way using custom scalar (https://www.graphql-tools.com/docs/scalars) and typing tags as JSON. See here: https://www.graphql-tools.com/docs/scalars#using-a-package
I am copying the example here for posterity
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 })
If you can, I would suggest choosing something like this:
#schema.gql
type App implements Node {
name: String!
tags: [ { name: String!, value: String! }! ]!
}