nuwave / nuwave/lighthouse

Allow defining type resolvers also for interface fields

Open
#2,718 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
3.5k
Forks
468
Avg merge
3h 9m
Merged PRs (30d)
2

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The proposal names GraphQL interface fields, implementing types, the @field directive, and the custom resolver Types\User\Url, but no files or tests. Start by locating the existing @field and interface-resolution behavior, then define the expected resolver inference and add coverage showing that implementing types no longer repeat the directive.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, laravel, php
Domain
api, backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.