graph-gophers / graphql-go

GraphQL server with a focus on ease of use
BSD 2-Clause "Simplified" License
4.65k stars 493 forks source link

How could i resolve this? #128

Open francescjaume opened 6 years ago

francescjaume commented 6 years ago

Hi!!

I have a question. I don't know how can I implements this schema:

schema{
    query: Query
    mutation: Mutation
}

type Query {
  admin: AdminQuery
}

type Mutation {
  admin: AdminMutation
}

Here the resolvers functions:

func (r* Resolver) Admin() *AdminMutationResolver {
    return &AdminMutationResolver{}
}
func (r* Resolver) Admin() *AdminQueryResolver {
    return &AdminQueryResolver{}
}

Thanks for all!!

lpalmes commented 6 years ago

Hey @francescjaume, do you have more information about this example? Like what is you AdminQuery and AdminMutation type in your schema, or what you are trying to achieve, so we can be able to help

francescjaume commented 6 years ago

Hi @lpalmes, we just need resolve admin in type Query and in type Mutation too. But Go raises us that we have same function (Admin) duplicated.

Our first solution is enable two diferent root resolvers like this:

func (r* MutationResolver) Admin() *AdminMutationResolver {
    return &AdminMutationResolver{}
}
func (r* QueryResolver) Admin() *AdminQueryResolver {
    return &AdminQueryResolver{}
}

We fork this aproach and it works good. Maybe you have some easier solution.

lpalmes commented 6 years ago

Yep, the problem is that root resolvers, like the ones inside Mutation, Subscription or Query object are bound to have name collisions, given that they all resolved by func (r *Resolver), i think what you are doing is good and a sensible solution, in my schema at least, i try to use verbs for mutation (eg: updateUser), and subjects for queries (users: [User]!), and i will take into account this solution if i ever need it, thanks!