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

Sohithanjan G
Kilo Sage
Kilo Sage

Hey @ab7289 

 

The error you're encountering indicates that the GraphQL server is not recognizing the "Filter" input type. This could be due to a few reasons. Here are some steps to troubleshoot the issue:

  1. Check Input Type Definition: Ensure that the Filter input type is correctly defined in your schema. In your case, it seems correctly defined, but it's always good to double-check for typos or missing parts.

  2. Namespace Issue: In your GraphQL query, you are using namepsace instead of namespace. Double-check if this is intentional or a typo. Correct it to namespace if needed.

 

query ($sys_id: String!, $filterQuestions: [Filter]){
    namespace {  // <-- Correct typo here
        recordProducerUtils {
            getFields(
                sys_id: $sys_id
                filterQuestions: $filterQuestions
            ) {
                sys_id
                value
                question {
                    sys_id
                    name
                    question_text
                }
            }
        }
    }
}

 

query ($sys_id: String!, $filterQuestions: [Filter]){ namespace { // <-- Correct typo here recordProducerUtils { getFields( sys_id: $sys_id filterQuestions: $filterQuestions ) { sys_id value question { sys_id name question_text } } } 
  • Ensure Filter Type is in the Correct Scope: Make sure the Filter type is defined in the appropriate scope within your GraphQL schema. If it's defined inside another type, it might not be accessible at the root level.

  • Restart or Clear Cache: If you've made changes to your GraphQL schema, restart your GraphQL server or clear any caching mechanisms that might be in place.

  • Check GraphQL Operation Name: Ensure that the operation name (e.g., query or mutation) in your GraphQL query matches the operation type specified in the schema. In your case, it should be a query.

After making these checks, if the issue persists, you might consider providing the entire GraphQL schema and any relevant server logs for further assistance. 

Mark as accepted solution if it suffices your requirement

Please mark as Accepted Solution if this solves your query and HIT Helpful if you find my answer helped you. This will help other community mates too..:)

Hi Sohith,

 

Thanks for your response. The 'namespace' namespace was an intentional typo, as I didn't want to include my company's namespace. Also I did provide the entire GraphQL schema (it is very small and purpose built). 

Is there a special way to restart the GraphQL server in ServiceNow? Or would that just be done by hitting the cache.do endpoint?

 

Thanks,

Alex

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]){
     ...
}

 

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]){
     ...
}