Giter VIP home page Giter VIP logo

Comments (8)

golaod avatar golaod commented on July 28, 2024

Is this also possible to nest Filter? cause it's not explained. E.g.

class ExtendedFilterType {
    /**
     * @Decorate(name="FilterWithColorInput")
     * @UseInputType(for="$nestedRelationFilter", name="NestedRelationFilterFactory")
     */
    public function createFilterWithColor(Filter $filter, Filter $nestedRelationFilter): Filter
    {
        $filter->addFilter('weight', '<', $maxWeight);
        $filter->addRelationFilters($nestedRelationFilter);
        return $filter;
    }
}

from graphqlite.

golaod avatar golaod commented on July 28, 2024

Also it doesn't actually say what happens with the input. Is it optional? Cause we can have 10 filters, but use only one in query.

from graphqlite.

moufmouf avatar moufmouf commented on July 28, 2024

Is this also possible to nest Filter?

Of course. It is already possible to nest an input type into another input type today. Since this is already supported, I did not write it explicitly.

Also it doesn't actually say what happens with the input. Is it optional? Cause we can have 10 filters, but use only one in query.

Yes, this is already something that GraphQLite can do today. I do not plan to change the current behaviour but that should be ok for you. If you want to make an input field optional, you simply make it nullable.

For instance:

public function createFilterWithColor(Filter $filter, ?Filter $nestedRelationFilter = null): Filter
{
    if ($nestedRelationFilter !== null) {
       $filter->addRelationFilters($nestedRelationFilter);
    }
    return $filter;
}

But now that you mention it, there is one thing missing in the issue. I must specify that the @UseInputType annotation can be used in the context of a @Factory and a @Decorate annotations.

from graphqlite.

golaod avatar golaod commented on July 28, 2024

Ok, there is one last problem I have.
We want to use classes as factory names, so it's easier to navigate through classes which extend input type and we actually found out that it partially works, but only one way. It goes to the factory class, but then it doesn't find an occurence of usage.

Is there a way for Factory, Decorate, UseInputType and ExtendType to be included in class usage?

Btw. is it valid annotation?

class MyFactory
{
  /**
   * @Factory(name=MyFactory::class)
   */
  public function create(int $something): Something;
}

from graphqlite.

moufmouf avatar moufmouf commented on July 28, 2024

Hey @golaod,

We want to use classes as factory names, so it's easier to navigate through classes which extend input type and we actually found out that it partially works, but only one way. It goes to the factory class, but then it doesn't find an occurence of usage.

In this proposal (this is not implemented yet), the "name" of the @Factory annotation represents the GraphQL Input type name.

Names in GraphQL (and input types in this particular class) must follow this Regex: /[_A-Za-z][_0-9A-Za-z]*/

See: https://graphql.github.io/graphql-spec/June2018/#sec-Names

As such, you cannot use "MyFactory::class" as a GraphQL input type name since it contains a "\".

If you want, I could slugify the name passed in parameter though, to make it compatible with the naming regex.

Is there a way for Factory, Decorate, UseInputType and ExtendType to be included in class usage?

I have no way to do this in GraphQLite. This is really an issue that should be opened to the authors of the "PHP Annotations" plugin of PHPStorm: https://github.com/Haehnchen/idea-php-annotation-plugin

from graphqlite.

golaod avatar golaod commented on July 28, 2024

Ok, the slugification would help

from graphqlite.

moufmouf avatar moufmouf commented on July 28, 2024

👍

from graphqlite.

moufmouf avatar moufmouf commented on July 28, 2024

For the record, instead of UseInputType, I'm going to name the annotation "Parameter".

Usage will be like this:

class PhoneController {
    /**
     * @Query
     * @Parameter(for="$filter", inputType="FilterWithColorInput!")
     */
    public function listPhones(Filter $filter): Grid {
        // ...
    }
}

I'm using the more generic "Parameter" name because in the future, I might reuse this annotation to bundle other annotations attached to the parameter. For instance:

class PhoneController {
    /**
     * @Query
     * @Parameter(for="$filter", inputType="FilterWithColorInput!", annotations={
     *            @Logged,
     *            @Right('CAN_FILTER')
     * })
     */
    public function listPhones(Filter $filter): Grid {
        // ...
    }
}

This will be better (and more performant) than having something like this:

class PhoneController {
    /**
     * @Query
     * @UserInputType(for="$filter", type="FilterWithColorInput!")
     * @LoggedParameter(for="$filter")
     * @RightParameter(for="$filter", name="CAN_FILTER")
     */
    public function listPhones(Filter $filter): Grid {
        // ...
    }
}

Indeed, I will be able to reuse the existing annotations (Logged, Right...) in the context of parameters (instead of the context of a method) and I do not have to do a lookup in the parameters list for each annotation.

from graphqlite.

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.