Does someone know how i can implement custom Type...
# orm-help
t
Does someone know how i can implement custom TypeResolver in prisma / graphql-yoga? I have a type Address nad i want that this resolver gets called on each place where this type is used
n
https://github.com/prismagraphql/graphql-server-example in this example are a couple of type resolvers 🙂
t
but i just see that i can write resolver for the fields
in graphql java it was possible to write one for the type self
and specify for fields if it is necessary
found something like this but is not working for me
Copy code
__resolveType(obj) {
      console.log(obj);
      return { country: 'Germany', zipcode: '70734' };
    },
imagine something like this
Copy code
Address: {
    __resolveType: async (parent, args, ctx: Context, info) => {
      return { country: 'Germany', zipcode: '70734' };
    },
    city: async (parent, args, ctx: Context, info) => {
      return 'Fellbach';
    }
  }
this is a type resolver
t
not exactly what i mean even here it is just a resolver for a field inside the type -> user -> field resolver
i would like to have a type resolver
and possible field resolver
imagine this:
Copy code
type Address {
  company: String!
  address: String!
  zipcode: String!
  city: String!
  state: String
  country: String!
  vat: String!
}
Copy code
export const Address = {
  resolve: async (parent, args, ctx: Context, info) => {
    return { country: 'Germany', zipcode: '70734', ... };
  },
  city: async (parent, args, ctx: Context, info) => {
    return // return the city from somewhere else;
  }
};
n
not sure what you mean then
t
so the ast tree is resolving first the type resolver and returns what it can and than possible field resolver if some exists
n
you need to return an object containing the city property from the resolve method
the City property can itself be a resolver again
t
it says that the resolve function is not an known field in address
compare to Feed here
t
it is another way to do but is not really scalable right -> imagine i am using the address in multiple places…than i have to write the function in multiple places?
of course i could reuse it but is it not better to have kind of type resolver directly? than i can define it onetimes in the right place and all other types which have a filed with the return type Address don’t have to do anything
n
No, you can write type resolvers once and they'll be called every time
t
ok 😞 but is there a technical reason why it is not working or spec reason? as i remember in graphql-java it is possible -> but its a long time and maybe not anymore possible 🙂
n
It's possible 🙂 I feel we might be talking past one another 😄
t
lets talk about it in berlin next week 😉
💯 1
Would like to understand
n
sure v
!
are you also coming to the community event Thursday night?
t
o didn heard about it 😄
where and when is it?
t
oh damn it we will arrive at 10 o’clock in the evening 😞
will be hard to join
n
haha oki
t
lets see