nicolasdao / schemaglue

Naturally breaks down your monolithic graphql schema into bits and pieces and then glue them back together.
BSD 3-Clause "New" or "Revised" License
116 stars 13 forks source link

Support for Unions #4

Closed williamluke4 closed 6 years ago

williamluke4 commented 6 years ago

Does schemaglue currently support graphql unions? Very helpful project thanks for all the work!

nicolasdao commented 6 years ago

Hi @williamluke4 ,

Thanks heaps for reaching out and reporting that issue. I'll work on this asap.

I'll let you know when that's done.

Cheers,

Nic

williamluke4 commented 6 years ago

Thanks @nicolasdao I was able to get it to work using __resolveType in the Unions resolver.

schema.js

union User= Admin_User| Foo_User

resolver.js

exports.resolver = {
   User:{
        __resolveType(obj, context, info){
            if(typeof obj.id === 'string'){
              return 'Admin_User';
            }
            return 'Foo_User';
        }
    }
}

`

nicolasdao commented 6 years ago

Hi @williamluke4 ,

You're completely right! Thanks a lot for this question and for answering it yourself 😍. I've just documented your feedback in the README.md to make it clearer to everybody.

In case you're interested, I've also open-sourced another project called graphql-s2s. It won't really help to manage unions, but it can make your schema definition more concise, readable and reusable. In a nutshell, it introduces the concept of inline inheritance, generic types and metadata. The feature that could help you with managing interfaces in your schema is the inheritance bit. You can check the documentation here.

Cheers,

Nic