Renaming of queries (newbie question)

Please is there a way to have a my own query names?
For example when I specify this type in my schema:

type Post {
  text: String
}

can I somehow have a custom named query definition, like this?

type Query {
  getPosts: Post
}

I know there are pre-generated queries (queryPost), but I can’t get over the naming. :frowning: Tried searching for custom queries but those seemed to be for external services.
Do I need a custom resolver, or directive? Sorry I don’t even know the proper lingo yet, still learning the basics.

Otherwise Dragph is just what I was looking for and would love to stay. I just need the feeling that I can have control over these seemingly simple things.

Thanks for any advice.

Are you just trying to rename the auto generated queries?

That’s exactly what I’m trying to do, but the editor didn’t allow me to do it. Got this message:

resolving updateGQLSchema failed because input:14: GraphQL Query and Mutation types are only allowed to have fields with @custom/@lambda directive. Other fields are built automatically for you. Found Query getPosts without @custom/@lambda.

So I tried to use @custom but failed, seemed like it’s for a different purpose

You cannot rename the auto-generated queries, but you can create new queries with your own names using @custom or @lambda. These don’t need to talk to external services, e.g., using custom DQL queries (docs).

1 Like

This post got locked, in the meantime via DM I explained custom queries, GraphQL vs DQL, difference between getType and query Type, and aliases. Turns out aliases was the solution. And FYI aliases are not in Dgraph’s GraphQL docs, but it is just basic GraphQL spec anyways.

3 Likes

Aliases are definitely the way to do it for reshaping the responses. Thanks, @amaster507!

1 Like

Had the same question yersterday and I’m using it now thank you guys,
In case it helps other noobs like me, this explanation is clear : How to use GraphQL aliases