Comments (11)
@olivernybroe Interesting, and I wonder if we even need a directive here... we could just have an internally defined Enum that the hasMany
, paginate
directive would check for and if it exists it would add it to he auto-generated query. Added it to v2.x
label!
from lighthouse.
@chrissm79 Hmm the problem I see with that is the hasMany
could end up being a little confusing with all the parameters.
For example if I want to give the user the power to choose if they want soft deleted models as well, how do I then define what the key in which they define that they want deleted models is called. eg. in the example above I called it trashed
.
However I think the hasMany
should have the opportunity to define soft deletes also, just as defaults instead.
from lighthouse.
@olivernybroe The schema is almost exactly as you have it, just w/out the directive (rather than adding another argument to the hasMany
directive). Like so:
# Lighthouse's schema
enum Trash {
ONLY @enum(value: "only")
WITH @enum(value: "with")
WITHOUT @enum(value: "without")
}
# User's schema
type Query{
companies(trashed: Trash): [Company!]! @paginate(model: "Company", type: "relay")
}
{
companies(first: 10, trashed: ONLY ) {
edges {
node {
id,
vat,
name
}
}
}
}
Then, using just the FieldInfo
the resolver would check if the Trash
enum was included in the arguments and pass it along to the query builder if so. This way you're not having to add an Enum
and a Directive
on the same field.
from lighthouse.
@chrissm79 Hmm I like the idea about looking at the FieldInfo
object instead, that's pretty awesome.
from lighthouse.
Hi all,
I'm looking for the same functionality
I thought I'd make a new Directive looking like:
<?php
namespace Nuwave\Lighthouse\Schema\Directives;
use Nuwave\Lighthouse\Schema\Directives\BaseDirective;
use Nuwave\Lighthouse\Support\Contracts\ArgBuilderDirective;
class WithTrashedDirective extends BaseDirective implements ArgBuilderDirective
{
public function name() : string
{
return 'withTrashed';
}
public function handleBuilder($builder, $value)
{
return $builder->withTrashed();
}
}
But this doesn't seem to do anything?
I thought the nicest way to use this was if we could use it as follows:
user(id: ID @eq): User @withTrashed @find
or
raises: [Raise!]! @withTrashed @all(model: "App\\Raise")
Does anybody know how to go about this, can't get this to work!
Thanks!
from lighthouse.
@gijsbeijer What you are trying to do is not the same. We wanted to do it as part of your query, it seems like you just want to always return the trashed models also.
I think your question belongs in the slack/spectrum chat instead, or as a new issue.
from lighthouse.
@olivernybroe sorry about that. Thinking of it, doing this via the query would be a lot nicer.
from lighthouse.
@gijsbeijer as the name implies, ArgBuilderDirectives
only work if they are applied to arguments.
What you are doing would require a new directive type, a way to hook into the builder through field directives.
from lighthouse.
This would be a great feature.
from lighthouse.
any updates here? I currently rely on this feature...
UPDATE I would like to implement this feature. I tried it locally, but I don't know, how to determine, that Trash
enum is used. @chrissm79 you mentioned FieldInfo
- how did you think to implement it? I was only able to get kind of argument, and it returns EnumValue
.
I would probably track the argument name, what is easier to me. We can improve it in my PR
from lighthouse.
@olivernybroe thanks to @lorado this is now a part of Lighthouse and will be released with the coming v4.3.0
from lighthouse.
Related Issues (20)
- Generate schema fail! HOT 1
- Exception Undefined array key "schemaExtensions" HOT 1
- Clear Cache (private) HOT 1
- Segmentation fault when handling large payloads HOT 8
- Requesting local scopes can pass parameters HOT 1
- New directive that mirrors functionality of `whereHas` for relations (not `@whereHasConditions`) HOT 1
- `make setup` failed on macOS
- Access context in `FieldMiddleware` HOT 3
- CanArgs is defined twice in schema-directives.graphql
- `extend scalar X` directives are lost
- @canFind is missing "model" argument in graphql definition HOT 1
- Allow to customize the unique key for `PaginatedModelsLoader`
- artisan lighthouse:union stub appears to be incorrect HOT 1
- Problem with subscription middleware HOT 2
- An error occurs in the SubscriptionRegistry when sending a subscription event via Subscription::broadcast with Laravel Octane (Swoole) HOT 4
- Laravel v11 support dependancy missing
- Enum Support for Morph Types HOT 1
- Mutation transaction seem not work HOT 4
- Failed to find class App\GraphQl\Queries\TodoQuery in namespaces [] for directive @paginate
- @whereNull and @whereNotNull No directive found!
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 lighthouse.