These are chat archives for graphql-java/graphql-java

7th
Sep 2018
Shrikant
@ShiniIn
Sep 07 07:00
Hi I have recently moved from graphQl version 6.0 to version 9.0. Now somewhere in backend i am converting the selection set(fields i want back in apis result) into JSON Array. Earlier the same code was working fine but now there are exception. I just want to know if there is any significant change in the storage pattern or something like that in projection items????
Brad Baker
@bbakerman
Sep 07 07:15
@ShiniIn - can you post an buffreport with stack traces - because there should be no major changes
Shrikant
@ShiniIn
Sep 07 08:03
@bbakerman I don't know if the stack traces are going to help as it has lots of garbage. However I have created a gist just to convey my problem. Please do have a look
Brad Baker
@bbakerman
Sep 07 08:35
please also create an issue if you find a real problem - we can remember based on chat conversation
identity/uuid is nothing that graphql-java the library will create
so what library wrappers are you using
eg graphql-java-tools etc...
also double cehck our own schemas - that looks like some one adda “uuid” field ata very rough guess
Arnab Datta
@arnabkd
Sep 07 10:37
Is there a guide on how to implement connections and edges in graphql-java?
Brad Baker
@bbakerman
Sep 07 10:37
not a guide - we have some Relay support classes
Arnab Datta
@arnabkd
Sep 07 10:37
As in what do I write in my schema.graphql for instance?
Brad Baker
@bbakerman
Sep 07 10:38
ahh use SDL and copy what the Relay spec says to do
Arnab Datta
@arnabkd
Sep 07 10:38
@bbakerman : maybe some examples then? :P
this is some really early work I did exploring Relay
I cant say its 100% right
for example it has no node(id) field on the top level query
which is not 100% relay compliant
but it has some code that deals with relay
so MAYbe it help kick start you
Arnab Datta
@arnabkd
Sep 07 11:01
Thanks
I guess… it doesn’t need to be 100% relay compliant for my part as all I really need is a way to count the number of hits, implement some basic ordering
and obviously, pagination
Brad Baker
@bbakerman
Sep 07 11:10
pagination is the challenge
in memory is easy peasy - we have classes for that
Shrikant
@ShiniIn
Sep 07 11:10
@bbakerman Okay but why it gets fail while i change the dependency of graphql-java only to 9.0. I mean havent changed anything other than that
Arnab Datta
@arnabkd
Sep 07 11:10
@bbakerman : How would you do pagination in postgres then?
Brad Baker
@bbakerman
Sep 07 11:11
but true relay style cursors are tricky
let me dig up and article on it
@ShiniIn - you have not descrived your exact problem not given any details on the exception and whats not working
I cant help you wtithout more concise details
Brad Baker
@bbakerman
Sep 07 11:18
I havent done any DB based “replay compliant” pagination in earnest - I think its about time I did
Arnab Datta
@arnabkd
Sep 07 11:23
Yeah I think this is one of the “problems” GraphQL users face because it is so agnostic in terms of datastore
Not really a cookie-cutter recipe for getting data from a given DB for a given language
Brad Baker
@bbakerman
Sep 07 11:25
that article talks about
SELECT * FROM posts
WHERE created_at < $after
ORDER BY created_at LIMIT $page_size;
In this case, the “after” cursor value is a timestamp, but it can be anything at all, as long as you can deserialize it into a starting point to fetch the next set of items. One particular benefit of having an encoded cursor with some metadata or a timestamp, rather than something like a row ID, is that it can be resilient to row deletion — we don’t want the query to fail if a specific item is removed. Timestamps and well-designed opaque cursors don’t have this issue.
so one of the pre-reqs of cursor based pagination is that you have that column to allow you to get a stable ordering that can also be examined in a > or < manner
Brad Baker
@bbakerman
Sep 07 11:40
on a side topic - this is a graphql truth bomb I read tonight
With GraphQL having a type system, we see a lot of tools appearing these days that try to generate GraphQL types from databases, ActiveRecord models, or a REST API. While this is tempting to use, and definitely useful at times, by copying our data model or an existing API, we forget to that GraphQL lets us really shape the interface we want to our domain. Try to use that power instead of shaping your API using your data’s shape as inspiration (Avoid Anemic GraphQL).
Marcel Overdijk
@marceloverdijk
Sep 07 11:44

is it possible to use nested property navigation when mapping the schema? E.g.:

.type("Department", typeWiring -> typeWiring
        .dataFetcher("id", departmentIdDataFetcher)
        .dataFetcher("country", departmentCountryDataFetcher)
        .dataFetcher("employees.country", employeeCountryDataFetcher))

In this case the employees.country registered fetcher is not working / kicking in. Note that employees is a list part of the retrieved department.

(I used this simplified model, as my actual model is different / more complicated)
Bojan Tomić
@kaqqao
Sep 07 11:46
@bbakerman Regarding the article you quoted above - YES! That's the number 1 point I try to drive home in every GraphQL talk I give.
That whole series of articles is great. I keep refering to them almost daily.
Bojan Tomić
@kaqqao
Sep 07 11:54

@arnabkd One hack is to simply treat after as offset, and first as count.
So

items(after: "20" first: 10) {...}

becomes e.g.

SELECT * FROM items LIMIT <after>, <first>
Marcel Overdijk
@marceloverdijk
Sep 07 12:01
Related to my above question, this works:
.type("Department", typeWiring -> typeWiring
        .dataFetcher("id", departmentIdDataFetcher)
        .dataFetcher("country", departmentCountryDataFetcher))
.type("Employee", typeWiring -> typeWiring
        .dataFetcher("country", employeeCountryDataFetcher))
The reason I was trying to used nested property my use case was a little but more complicated and tried to use some shortcut
Let me try to explain.
The Employee types implements a Person class. The person has a country.
Next to that the Department type has other lists like students, alumniwhich are all specific types implementing Person.
I was hoping to find a to define / configure the Country data fetch for all person types
I tried something like:
.type("Person", typeWiring -> typeWiring.typeResolver(personTypeResolver)
                        .dataFetcher("country", personCountryDataFetcher))
but that didn't seem to work
Is the only way to define the country data fetcher for all specific person types then?
Marcel Overdijk
@marceloverdijk
Sep 07 12:06
(it is doable but much more configuration)
PS: the Person type resolver I needed to configure anyway