1

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!

1 Answer 1

1

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! }! ]!
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.