Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fields are null when introspecting Input Types #330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gordon-soh opened this issue Mar 9, 2021 · 1 comment
Closed

Fields are null when introspecting Input Types #330

gordon-soh opened this issue Mar 9, 2021 · 1 comment

Comments

@gordon-soh
Copy link

Hi, thanks for creating GraphQLite!

I have an issue when creating an Input Type - if we use introspection to inspect it the fields are always null.

I have tried creating an Input Type using the @Factory annotation, like so:

use TheCodingMachine\GraphQLite\Annotations\Factory;

class AddressInputType
{
    /**
     * @Factory(name="AddressInput", default=true)
     *
     * @param string $line1
     * @param string $postcode
     *
     * @return Address
     */
    public function createAddress(string $line1, string $postcode): Address
    {
        $address = new Address();
        $address->setLine1($line1);
        $address->setPostcode($postcode);
        return $address;
    }
}

And also using the @Input annotation from @devmaslov's PR (#269), like so:

use TheCodingMachine\GraphQLite\Annotations\Field;
use TheCodingMachine\GraphQLite\Annotations\Input;

/**
 * @Input(name="AddressInput", update=true)
 */
class AddressInputType
{
    /**
     * @Field()
     *
     * @var string
     */
    public string $line1;

    /**
     * @Field()
     *
     * @var string
     */
    public string $postcode;
}

But, when POSTing the following introspection query:

query {
    __type(name: "AddressInput") {
        name,
        fields {
            name,
            type {
                name
                kind
            }
        }
    }
}

The response is:

{
    "data": {
        "__type": {
            "name": "AddressInput",
            "fields": null
        }
    }
}

Is this is a bug, or am I doing something incorrectly here?

I can see the fields are being detected and added to the Input Type in InputTypeGenerator.php at line ~66 (mapInput()) but it looks like somewhere down the call-stack the fields are being set to null.

Any advice would be highly appreciated!

@gordon-soh
Copy link
Author

It turns out this is actually correct - according to the GraphQL spec (https://github.com/graphql/graphql-spec/blob/main/spec/Section%204%20--%20Introspection.md), for INPUT_OBJECTs the fields should always be null and instead we should be looking at inputFields.

query {
    __type(name: "AddressInput") {
        name,
        inputFields {
            name,
            type {
                name
                kind
            }
        }
    }
}

The response is:

{
    "data": {
        "__type": {
            "name": "AddressInput",
            "inputFields": [
                {
                    "name": "line1",
                    "type": {
                        "name": null,
                        "kind": "NON_NULL"
                    }
                },
                {
                    "name": "postcode",
                    "type": {
                        "name": null,
                        "kind": "NON_NULL"
                    }
                }
            ]
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant