in reply to Converting a GraphQL schema into Perl classes

Thunking is a way of deferring evaluation, so for instance you can specify a GraphQL thing that has a field that's an array of those same things even though at that moment the "thing" isn't valid yet.
I need to convert this schema to Perl Classes which each can take a JSON response and populate their corresponding object with that.
I don't believe that you do need that. What would you gain by doing so? GraphQL is all about APIs that can evolve without major-versioning, which means that these classes would need to constantly change too. I made the Perl GraphQL using OO because it seemed like a good idea, and I'd do it that way again. But I believe that OO programming must earn its keep, not be the default.

Your specific issue here may be that those "Ratio" things are GraphQL "scalar" types, and the Perl code isn't really set up to know what to do with those just with SDL information. In particular, the Perl GraphQL modules are very much for making a server-side service, and you are making client-side code. That doesn't need to know the whole schema. It only needs to know the particular query/queries to fill its own information needs. See, as linked in the "SEE ALSO" section of the GraphQL docs, http://graphql.org/graphql-js/ and the graphql-perl port at http://blogs.perl.org/users/ed_j/2017/10/graphql-perl---graphql-js-tutorial-translation-to-graphql-perl-and-mojoliciousplugingraphql.html.

  • Comment on Re: Converting a GraphQL schema into Perl classes

Replies are listed 'Best First'.
Re^2: Converting a GraphQL schema into Perl classes
by bliako (Abbot) on Aug 30, 2024 at 18:24 UTC

    thanks for your answer. I beg to differ on the merits of OO even in a lowly client. I prefer to have a nested bunch of OO objects which know how to print themselves rather than printing a hash which can be different given different input toggles. Or they know how to return their part of a bigger query. Anyway, in prototyping I worked with the json/perlhash and know that that will not fly in the long run re:maintenance and brain rot.

    On the particular error, there is a declaration: scalar Ratio but that does not seem to be picked up. I have replaced Ratio with a Float but then other errors occured as there are quite a few typedefs like Ratio.