Giter VIP home page Giter VIP logo

Comments (11)

chrissm79 avatar chrissm79 commented on June 21, 2024

@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.

olivernybroe avatar olivernybroe commented on June 21, 2024

@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.

chrissm79 avatar chrissm79 commented on June 21, 2024

@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.

olivernybroe avatar olivernybroe commented on June 21, 2024

@chrissm79 Hmm I like the idea about looking at the FieldInfo object instead, that's pretty awesome.

from lighthouse.

gijsbeijer avatar gijsbeijer commented on June 21, 2024

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.

olivernybroe avatar olivernybroe commented on June 21, 2024

@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.

gijsbeijer avatar gijsbeijer commented on June 21, 2024

@olivernybroe sorry about that. Thinking of it, doing this via the query would be a lot nicer.

from lighthouse.

spawnia avatar spawnia commented on June 21, 2024

@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.

luispittagros avatar luispittagros commented on June 21, 2024

This would be a great feature.

from lighthouse.

lorado avatar lorado commented on June 21, 2024

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.

spawnia avatar spawnia commented on June 21, 2024

@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)

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.