Postman Graphql Schema Refresh not working - graphql

I am using postman for my qrpahql requests with spring boot.
When i try to refresh the schema my application gave an error.
graphql.AssertException: query can't be null
at graphql.Assert.assertNotNull(Assert.java:17)
at graphql.ExecutionInput$Builder.query(ExecutionInput.java:204)
at
graphql.kickstart.execution.input.GraphQLSingleInvocationInput.createExecutionInput(GraphQLSingleInvocationInput.java:47)
This is because postman sends the refresh query empty. Could you fix it #Postman Team
The query should be like this;
query IntrospectionQuery {
__schema {
queryType {
name
}
mutationType {
name
}
subscriptionType {
name bla bla bla

Related

Empty data in AWS AppSync GraphQL subscription event

I have an application that uses a GraphQL API, provided by the AWS AppSync service. It uses GraphQL subscriptions to send messages between different clients in near real time. There is a mutation pushItems that's configured with a resolver, which has a 'none' data source and forwards the request data unmodified to the subscription onItemChange.
The app hasn't been used for a couple of years, and now when I attempt to trigger a subscription event, I get an error on the subscribed client. Previously this worked without issues.
{
"data": {
"onItemChange": null
},
"errors": [
{
"message": "Cannot return null for non-nullable type: 'ID' within parent 'Item' (/onItemChange/id)",
"path": [
"onItemChange",
"id"
]
}
]
}
The error message suggests that the property id within the Item object is null, however when I send a mutation from the AWS AppSync web console with a hard-coded string for the item ID, I still get the same issue, even though the mutation response contains the correct data that should be forwarded to the subscribed client.
I've created a minimal configuration in AWS AppSync to reproduce the issue, which is detailed below. Is it possible that the AppSync service has changed the way it handles subscription data in the last few years?
GraphQL schema
schema {
query: Query
mutation: Mutation
subscription: Subscription
}
type Query {
getItem(id: ID!): Item
}
type Mutation {
pushItems(
items: [ItemInput]
): [Item]}
type Subscription {
onItemChange: Item
#aws_subscribe(
mutations: [
"pushItems"
]
)
}
type Item {
id: ID!
}
input ItemInput {
id: ID!
}
Resolver mappings for mutation pushItems
Request:
{
"version" : "2017-02-28",
"payload": $util.toJson($context.arguments.items)
}
Response:
$util.toJson($context.result)
Example queries
The following queries can be used to reproduce the issue in the AWS AppSync web console. First, subscribe to onItemChange:
subscription MySubscription {
onItemChange {
id
}
}
Then (in a different browser tab) send some data to pushItems:
mutation MyMutation {
pushItems(items: [{id: "foo"}]) {
id
}
}
You are returning Set of items in the mutation so you should update subscription return type to [Item]
type Subscription {
onItemChange: [Item] <--- HERE
#aws_subscribe(mutations: ["pushItems"])
}

How to extract a operation from Graphql Request

I am trying to fetch a user from graphql playground which has both queries , when i hit the fetch button and select GetUser it still send send both query as string to server.
My question is how to extract all data / fragments / query on backend related to one operation in this case it's GetUser because this query is sent to other service from backend which doesn't have CreateUser implementation and query fails. I am currently using NestJs
mutation CreateUser ($input: CreateUserInput) {
createUser (input: $input) {
... on User {
id
}
}
}
query GetUser ($input: GetUserInput) {
getUser (input: $input) {
... on User {
id
}
}
}

WPGraphQL Query by URI returns null on custom post type

I have a custom post-type that I am trying to query by URI, my query looks like this but doesn't work:
query {
article(id:"/category/child-category/article-name/", idType:URI) {
slug,
uri
}
}
If I do the same using the DATABASE_ID to verify the article URI, it works just fine:
query {
article(id:4843175, idType: DATABASE_ID) {
slug,
uri
}
}
this bug has been addressed in v0.12.3 https://github.com/wp-graphql/wp-graphql/releases/tag/v0.12.3

Postman, test Graphql response

I have this query:
query SessionQuery {
cliente {
id
clienteId
rut
porcentajeDeCompletitudDeInformacion
fichaCliente {
tipoPersona
razonSocial
}
representantesLegales {
edges {
node {
rutRepresentante
}
}
}
documentosRequeridos {
edges {
node {
iDDocumento
cargado
nombreDocumento
tipoDocumentoHQB
}
}
}
}
usuario {
id
usuarioId
email
nombre
rut
}
}
I'm testing for the first time GraphQL through Postman, like this way:
I'm having this response, I don't understand the error message:
{"data":{"cliente":{"id":"Q2xpZW50ZTow","clienteId":0,"rut":"XXX","porcentajeDeCompletitudDeInformacion":20,"fichaCliente":{"tipoPersona":2,"razonSocial":"ING. Y SISTEMAS BIZWARE (Empresa Relacionada)"},"representantesLegales":{"edges":[{"node":{"rutRepresentante":null}}]},"documentosRequeridos":{"edges":[]}},"usuario":{"id":"VXN1YXJpbzoyMDI4","usuarioId":2028,"email":"XXXX#gmail.com","nombre":"XXXX","rut":"XXXX"}},"errors":[{"message":"GraphQL.ExecutionError: Cannot return null for non-null type. Field: rutRepresentante, Type: String!.\r\n at GraphQL.Execution.ExecutionStrategy.ValidateNodeResult(ExecutionContext context, ExecutionNode node)\r\n at GraphQL.Execution.ExecutionStrategy.ExecuteNodeAsync(ExecutionContext context, ExecutionNode node)","locations":[{"line":14,"column":11}],"path":["cliente","representantesLegales","edges","0","node","rutRepresentante"]}]}
I not sure what it means the error. My problem is when I call this Graphql endpoint from JavaScript I have a CORS problem in my app, but I detected with Postman that maybe the problem is this one, and the query or something is broken. Any idea please, thanks.
xadm's comment is correct - in a standard GraphQL schema, the exclamation point means that the field is required. It's likely that the rutRepresentante field is NULL for the database record that your query retrieves.
Either remove the exclamation mark from String! in order to make the field nullable, or populate the row in the database for the rutRepresentante column (or key, if you're not using SQL...)

readQuery from cache results in Can't find field <field> on object undefined

I'm getting started with graphQL and apollo. I'm doing some simple queries and mutations fine but when I try to access data from apollo cache I keep getting "Can't find field me on object undefined" but when using apollo chrome plugin it returns data correct.
When logged into my app I run a simple query that fetches the user object from the server. It logs correct, I can see in chome dev apollo under queries and cache that my user data is there.
const ME_QUERY = gql`
query {
me {
_id
username
password
exchanges {
name
active
}
}
}
`;
<Query query={ME_QUERY}>
{({loading, error, data}) => {
if (error) {
return <Error error={error.message} />;
}
if (data) {
console.log(data, 'data');
}
return <div>asdf</div>
}}
</Query>
I have wrapped withApollo and I can log the client object fine in the component where I'm trying to query. I run the following code:
componentDidMount() {
console.log(this.props.client.readQuery, 'propps');
const user = this.props.client.readQuery({
query: gql`
{
me {
_id
username
password
exchanges {
name
active
}
}
}
`
});
console.log(user, 'user');
And that results in Uncaught Error: Can't find field me on object undefined Ive also tried with adding variables but it doesn't help.
Which object is undefined? Any idea why my query fails?
You are probably using Apollo Client > 2.5 which handles state locally.
Read the migration guide for more information.
Use the default client resolver to resolve your local state
Use cache.write to write default data into your cache. This is the part of the migration that causes your crash.

Resources