Data not mapped schema graphql

Asked

Viewed 43 times

0

I would like to ask a question about Graphql.

I have an API that receives certain data from the user, for example: Name, email, address and etc... and in addition to this already predefined data, it is possible to save additional data, which is not defined. The following question arose:

How do I define the type of this data, because I could not find in the documentation a type "object".

For example:

    type Query {
    user: User
}

type User {
    id: ID!,
    name: String,
    email: String,
    extra: Object //este seria um objeto customizado
}

Does anyone know how I can solve?

1 answer

2


In GraphQL all data has to be an object json valid, ie, must have key and value.

One of the ways to map the data would be to define a type with the respective values:

type UserExtra {
  valor1: String,
  valor2: Number,
  ...
}

type User {
    id: ID!,
    name: String,
    email: String,
    extra: UserExtra
}

But to use this format you have to know the key of the values returned in extra(valor1, valor2...).

If you don’t know the key of the values returned in extra can define a Scalar Type for the type json using the library graphql-type-json, thus the values in extra will be mapped as json.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.