Error Resolving GraphQL Schema

ab7289
Tera Contributor

I have created a simple GraphQL API to allow retrieval of values from the question_answer table. The schema is relatively simple with a couple types and inputs.

 

 

schema {
    query: Query
    mutation: Mutation
}

type Question {
	sys_id: String! @source(value: "sys_id.value")
	name: String! @source(value: "name.display_value")
	type: String @source(value: "type.display_value")
	cat_item: String @source(value: "cat_item.value")
	question_text: String @source(value: "question_text.display_value")
}

type Field {
	sys_id: String! @source(value: "sys_id.value")
	question: Question @source(value: "question.value")
	value: String! @source(value: "value.value")
}

type SetFieldsResponse {
	error: Boolean
	message: String
}

input Filter {
	field_name: String!
	value: String!
}

input FieldInput {
	value: String!
	parent_id: String!
	field_name: String
	field_id: String
}

type Query {
   getFields(sys_id: String!, filterQuestions: [Filter]) : [Field]
}

type Mutation {
    setFields(fields: [FieldInput]) : SetFieldsResponse
}

 

 

 

The issue that I am running into is it doesn't seem like type resolution for the defined Filter input type is not working. When I query the API from postman with the following:

POST https://{instance}.service-now.com/api/now/graphql

Query:

 

query ($sys_id: String!, $filterQuestions: [Filter]){
    namepsace {
        recordProducerUtils {
            getFields(
                sys_id: $sys_id
                filterQuestions: $filterQuestions
            ) {
                sys_id
                value
                question {
                    sys_id
                    name
                    question_text
                }
            }
        }
    }
}

 

 with the GraphQL Variables specified as:

 

{
    "sys_id": "e4db34e11b2df110350efe261a4bcb28",
    "q_id": "dd042ff01bb06510350efe261a4bcb8f",
    "filterQuestions": [
        {
            "field_name": "sys_id",
            "value": "dd042ff01bb06510350efe261a4bcb8f"
        }
    ]
}

 

 

Unfortunately the response I receive back is:

 

{
    "data": null,
    "errors": [
        {
            "message": "Validation error of type UnknownType: Unknown type Filter",
            "errorType": "ValidationError",
            "locations": [
                {
                    "line": 1,
                    "column": 45
                }
            ],
            "validationErrorType": "UnknownType"
        }
    ]
}

 

I feel like there is a silly mistake hidden somewhere in here but I have not been able to find it, any help would be greatly appreciated.

1 ACCEPTED SOLUTION

Gregory Mote
Kilo Guru

In your query parameter you may need to prepend Filter with the application namespace and schema namespace using underscores

 

 

query ($sys_id: String!, $filterQuestions: [namepsace_recordProducerUtils_Filter]){
     ...
}

 

 

View solution in original post

5 REPLIES 5

This worked! I knew it must be something simple, thank you so much!.