- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2023 08:55 AM - edited 11-17-2023 08:56 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2024 10:51 AM
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]){
...
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2023 11:15 AM - edited 11-18-2023 11:17 AM
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:
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.
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
}
}
}
}
}
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 07:21 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2024 10:48 AM
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]){
...
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2024 10:51 AM
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]){
...
}