Skip to content

Allow defining type resolvers also for interface fields #2718

@djibarian

Description

@djibarian

What problem does this feature proposal attempt to solve?

When defining types that implement an interface is very verbose having to specify the resolver on each of the type fields when using a custom resolver. Look at this example:

# User interface

interface User {

	accountType: AccountType! @rename(attribute: "account_type")
	id: UserId!
	name: String!
	url(lang: String!): String!

}

# UserGroup type

type UserGroup implements User {

	accountType: AccountType! @rename(attribute: "account_type")
	id: UserId!
	name: String!
	url(lang: String!): String! @field(resolver: "App\\GraphQL\\Types\\User\\Url")

}

# UserPersonal type

type UserPersonal implements User {

	accountType: AccountType! @rename(attribute: "account_type")
	id: UserId!
	name: String!
	url(lang: String!): String! @field(resolver: "App\\GraphQL\\Types\\User\\Url")

	firstName: String! @rename(attribute: "first_name")
	lastName: String! @rename(attribute: "last_name")

}

That @field directive in the types is repetitive and ugly, because is not even possible to use a short form like User\\Url.

Which possible solutions should be considered?

Would be good if this would be automatically inferred, avoiding the need to use the @field directive. In the example, the custom resolver is placed in Types\User\Url, denoting that the resolver is common to any type implementing User.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions