Multiple element type

25 views
Skip to first unread message

Ros

unread,
May 14, 2018, 8:46:18 AM5/14/18
to sangria-graphql
Hi There,

I have been trying to see how to make below works with sangria.

I have a class User(name, email)
so, I have type for sangria: UserType

I have another class Team(name, description)

And a class Record(id, name, owners) => Here the owners can be list of team and user

What I want to have is a type that can return Record along with its list of User and Team associated with it.

Thanks in advance,
Ros

Oleg Ilyenko

unread,
May 15, 2018, 8:13:12 PM5/15/18
to sangria-graphql
Hi Ros,

Would be happy to help you on this one, but I find the question is quite broad. Have you already checked the getting started page and the material listed in the "Next Steps" section at the bottom:


"How To GraphQL” tutorial (it covers a lot of topics) and “Zero To GraphQL” example are quite good and might be helpful in this scenario as well.

Cheers,
Oleg

Ros

unread,
May 22, 2018, 11:20:33 AM5/22/18
to sangria-graphql
Hi Oleg,

Thank you for your reply. I managed to solve it with workaround. 

One more thing I need to ask is "is there anyway we can ignore the fields when they are null or empty?" 

Thanks again,
Roshan

Oleg Ilyenko

unread,
May 22, 2018, 12:16:20 PM5/22/18
to sangria-graphql
Hmmm, I'm not 100% sure what you mean by  "ignore the fields", I think a bit of a context would help. It would be great if you could show it on a small example.

Ros

unread,
May 22, 2018, 1:20:23 PM5/22/18
to sangria-graphql
{
    "data": {
        "users": [
            {
                "id": "5b02ce90aadd477013855333",
                "company": null,
                "name": "Adam Smith"
            }
...

In above response example, instead of getting null if value doesn't exists in server, I am in need to completely ignore the field company.

So, my desired output will be like this:
{
    "data": {
        "users": [
            {
                "id": "5b02ce90aadd477013855333",
                "name": "Adam Smith"
            }
...

Is it possible ?

Oleg Ilyenko

unread,
May 22, 2018, 5:05:39 PM5/22/18
to sangria-graphql
I see, it's about the output fields, thanks for the clarification. I afraid that this behavior is the part of the GraphQL specification. Removing these might be dangerous since other spec-compliant tools and libraries might rely on the presence of fields with a `nulll` value in the response.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages