Error in Vue graphql: Missing query attribute on result - graphql

I want to have multiple queries in one network request. I have put all my queries in vue Apollo but I get this error when data revived(I will get the data in network tab but I cant access it!)
error: vue-apollo.esm.js?522d:842 Missing query attribute on result
code:
apollo: {
query: gql`
query {
query1 {someValue}
query2 {someValue}
}
`
}

Related

Can we pass dynamic schema details in GraphQL query which can be used by JoinMonster?

I'm not sure if passing the schema name as an argument in the GraphQL query will work for JoinMonster or not. Following is the query example:
{
configuration_queries(table: 'xyz', where: 'some condition') {
data {
col1
col2
}
}
}
so here it is expected to create a dynamic query on "xyz" table using JoinMonster.
Yes, it's possible to pass schema details dynamically to GraphQL queries. There are a few different ways to do this, but one approach would be to use the graphql-tools package:
Install the graphql-tools package:
npm install --save graphql-tools
Write your GraphQL query, using the graphql-tools syntax for dynamic schema details:
const query = `
query($schema: String!) {
joinMonster(sql: $schema)
}
`;
Call the graphql function, passing in your query and dynamic schema details:
const schemaDetails = `
SELECT * FROM users
JOIN posts ON users.id = posts.user_id
`;
graphql(query, { schema: schemaDetails })
.then((result) => {
// handle results...
})
.catch((error) => {
// handle errors...
});

Cannot query field \"xxx\" on type \"Query\".",

I have a GraphQL server built with apollo-server and i am getting this error. The query works correctly on apollo graphql studio, but I get the error when I try fetching the data in my React application.
const GET_VEHICLE_MAKES = gql`
query {
vehicleMakes {
id
make
}
}
`;
const { loading, error, data } = useQuery(GET_VEHICLE_MAKES);

GraphQL Relay introspection query fails: Unknown field '__type' on type 'Query'

I have a React application with a GraphQL client (Relay).
I need to make an introspection query to get all the types of a certain enum.
This is my query:
import { graphql } from 'react-relay'
export const corporationTypeEnumQuery = graphql`
query corporationTypeEnumQuery {
__type(name: "CorporationTypeEnum") {
enumValues {
name
}
}
}
`
When I try to compile the app, Relay throws the following error:
Unknown field '__type' on type 'Query'
When I try the exact same query on GraphIQL (the playground that the server offers me), there is no error, and the query is successful.
Please tell me what could be wrong with my GraphQL query. Any suggestions are well received.
The __type must be part of your schema. Graphql spec by default said this should be hidden and not part of schema.. You need to extend your server to expose it or manually put them to schema..
Server can handle that but compiler not since it require explicit definition in .graphql

Why is my graphQL query returning results without `where` filters?

I am working on a webapp with a nuxt/vuetify/apollo frontend. The backend is a strapi (v3.0.0-beta.18) server with a graphQL endpoint and a mongoDB database (v4.2.2)
It could be a newbie question since it's my first graphql project. I have a query for a collection called tags. It looks as follows:
query Tags($search: String, $selected: [ID], $limit: Int) {
tags: tags(
limit: $limit
sort: "score:desc"
where: { name_contains: $search }
) {
id
name
description
type
}
selected: tags(where: { id_in: $selected }) {
id
name
description
type
}
}
That query is returning every result that should be filtered by the where object, while the sort and limit filters work. The behavior is the same in my frontend app and on the graphQL playground. Am I missing something?
Note that strapi Shadow CRUD feature is enabled.
It turns out that I missed one of the breaking changes when upgrading strapi to the latest version. The mongose connector changed its name: https://strapi.io/documentation/3.0.0-beta.x/migration-guide/migration-guide-beta.17-to-beta.18.html

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