Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use distinct in GraphQL query?

Tags:

graphql

Here is query where I try to use distinct in graphQl query:

query{
    contacts(take: 10, distinct: true) {
        firstName
        lastName
        title
    }
}

But I am getting error:

{
    "errors": [
        {
            "message": "Unknown argument \"distinct\" on field \"contacts\" of type \"QuerySchema\".",
            "locations": [
                {
                    "line": 2,
                    "column": 21
                }
            ]
        }
    ]
}
like image 478
user207888 Avatar asked Oct 03 '17 19:10

user207888


People also ask

What is __ Typename in GraphQL?

The __typename field returns the object type's name as a String (e.g., Book or Author ). GraphQL clients use an object's __typename for many purposes, such as to determine which type was returned by a field that can return multiple types (i.e., a union or interface).

What are the 2 most common actions in GraphQL?

From the point of view of the client, the most common GraphQL operations are likely to be queries and mutations.

How does query work in GraphQL?

GraphQL is a query language for your API, and a server-side runtime for executing queries using a type system you define for your data. GraphQL isn't tied to any specific database or storage engine and is instead backed by your existing code and data.


1 Answers

GraphQL has no built-in sorting/filtering. It is up to the server to implement features like that, so if you're relying on a third party API and it doesn't support it then you will have to filter the response yourself.

like image 117
Tom Avatar answered Sep 20 '22 14:09

Tom