Comments (6)
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.
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.
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.
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.
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.
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)
- Tests are failing on CI HOT 3
- Cannot upgrade to laravel 10x because it cannot coexist with rebing dependency illuminate/contracts and illuminate/support
- Playground, are you thinking of implementing it?
- Unable to enable apq caching
- Is there documentation on returning objects with relation objects as a part of the type? HOT 4
- Pagination on Relation HOT 1
- Unexpected end of JSON input HOT 3
- queryContext in GraphQLController doesn't exist HOT 2
- L11: Unresolvable dependency resolving [Parameter #4 [ <required>; string $basePath ]] in class Illuminate\Foundation\Exceptions\Renderer\Renderer (500 Internal Server Error) HOT 1
- Improve error reporting when a type's name has illegal characters HOT 2
- Custom Query Fails to Load in Laravel 11 with graphql-laravel
- Add support for thecodingmachine/safe 2.0 HOT 2
- Nullable and Filled
- Resolver context is not updated once a user is logged in HOT 2
- repo description nit
- Pagination error HOT 2
- Integration tests for L9 are not working anymore
- useing $args in the resolve cloture of a type item
- Missing parent table in SelectFields for UnionType and InterfaceType HOT 3
- Using getRelations of SelectFields involves only selecting the requested fields for relationships HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql-laravel.