Skip to content

custom scalar Object is coerced to empty object #1682

@mohitjaimini9

Description

@mohitjaimini9

Hi Team,

I have used custom scalar Object/Json to receive a input json in the mutation. Use case is to keep value field a generic once where Any custom json object can be sent.

type Entry {
  key: String!
  value: Object!
}
type Mutation {
     saveEntry(entry: Entry!): Object!
}

Example mutation call looks like following:

mutation {
    saveEntry(entry : {
        key: "order",
        value: {
            id: "123",
            type: "mobile"
            payment: {
                method: "Cash"
                amount: "1212"
            }
        }
  })
}

I have also defined customHooks as follows:

override fun willGenerateGraphQLType(type: KType): GraphQLType? = when (type.classifier as? KClass<*>) {
    Any::class -> graphqlObjectType
    JsonObject::class -> ExtendedScalars.Json
    else -> null
}

After doing all this, In mutation handler, i receive an empty object {} in value field. Can you please help me understand how can this be resolved ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions