0

I was wondering, is there a way to apply the types declared in our Graphql API to format data the same way graphql does it with the return value if a query.

There are other ways to do that, (like having an actual formatting service that would sit between the returned value of the query and the type itself) but I really would like to know how to format from the type directly (without making my own internal gql query).

I currently do it by executing an internal graphql query that is fired internally but that's not really what I'd like.

Edit: Add example of what I have in mind

class Types::UserType < Types::BaseObject field :id, ID, null: false field :custom_id, ID, null: false def custom_id object.id + context["id_suffix"] end end typed_object = Types::UserType.new(User.find(1), { "id_suffix" => "foo" }) # this is pseudo code, that's the part I'd like to know how to do typed_object.custom_id #=> "1foo" typed_object.to_h #=> { "id" => 1, "custom_id" => "1foo" } 
3
  • Can you share an example of what you want to achieve? Commented Apr 19, 2023 at 20:45
  • @Pipetus just edited the post with an example. Commented Apr 27, 2023 at 3:09
  • check it out I find this very useful github.com/kashiftufail/graphql_api_nested Commented Jun 7, 2023 at 10:53

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.