Giter VIP home page Giter VIP logo

Comments (6)

rebing avatar rebing commented on August 15, 2024

I haven't tried using interfaces with GraphQL, so I'm not sure how it sould work. How do you define the fields separately (outside the fields function) to be implemented? Could you please show me code of the class and interface.

from graphql-laravel.

HenriksenTeamBlue avatar HenriksenTeamBlue commented on August 15, 2024

I made a simple example to demonstrate. There's nothing fancy going on when resolving individual fields:

interface:

`class TestInterface extends InterfaceType {

protected $attributes = [
    'name' => 'TestInterface',
    'description' => 'Test interface',
];

public function fields()
{
    return [
        # Fields
        'type' => [
            'type' => Type::string(),
            'description' => 'the type',
        ],
        'field1' => [
            'type' => Type::string(),
            'description' => 'field 1',
        ]
    ];
}

public function resolveType($root) {
    return GraphQL::type('TestObject');
}

}`

Test type:

`class TestObject extends GraphQLType {

protected $attributes = [
    'name'          => 'TestObject',
    'description'   => 'A test object',
    'model'         => Test::class,
];

public function fields()
{
    return [
        # Fields
        'type' => [
            'type' => Type::string(),
            'description' => 'the type',
        ],
        'field1' => [
            'type' => Type::string(),
            'description' => 'field1',
        ],
        'field2' => [
            'type' => Type::string(),
            'description' => 'field2',
        ]
    ];
}

public function interfaces() {
    return [
        GraphQL::type('TestInterface')
    ];
}

}`

from graphql-laravel.

HenriksenTeamBlue avatar HenriksenTeamBlue commented on August 15, 2024

Just a quick note I tried switching to the Folklore package which your version is based on at it runs fine on that, so it looks like there is a bug here.

from graphql-laravel.

rebing avatar rebing commented on August 15, 2024

Ah, I didn't even remember the interfaces function was a possibility. I will try to find the time to look into it over the weekend.

from graphql-laravel.

rebing avatar rebing commented on August 15, 2024

I couldn't currently find the bug and unfortunately don't have too much spare time to deal with this. But if you can figure it out, feel free to submit a PR :)

from graphql-laravel.

RSchwan avatar RSchwan commented on August 15, 2024

I digged a bit into the code and it seems the problem is in the SelectFields class. It tries to fetch all selectable fields but it only knows it's from type TestInterface. It tries to find the field field2 but can't find it because the interface isn't yet resolved to TestObject.
I think it can be fixed by selecting all fields of possible casts (i.e. ... on TestObject).
But I don't know if such a function exists to get all possible cast.

from graphql-laravel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.