Search code examples
graphqldirectus

Directus - Retrieve relations with GraphQL


I try to retrieve the relations of the database of my directus app.

I use GraphQL with following endpoint https://myapp.directus.app/graphql.

Using a query for the relations according to the docs

query {
    relations {
        collection
        field
    }
}

leads to an validation error:

{
    "errors": [
        {
            "message": "GraphQL validation error.",
            "extensions": {
                "code": "GRAPHQL_VALIDATION_EXCEPTION",
                "graphqlErrors": [
                    {
                        "message": "Cannot query field "relations" on type "Query". Did you mean "locations"?",
                        "locations": [
                            {
                                "line": 2,
                                "column": 2
                            }
                        ]
                    }
                ]
            }
        }
    ]
}

I use Postman so far and started with a query for the database entries

query { 
    boards { 
        id 
        columns {
            id
            name
        }
    }
}

which works as expected.

What I find interesting is, that Postman shows an mouseover text on the keyword "relations" of the 2nd query -->

"Cannot query field relations on type Query. Did you mean locations?"

But unfortunately I have no idea what to do with that message.

Any ideas what is wrong here?


Solution

  • Meanwhile I found the problem. The endpoint for queries on relations is https://myapp.directus.app/graphql/system

    With that the query

    query {
        relations {
            collection
            field
        }
    }
    

    is working