Comments (8)
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.
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.
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.
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.
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.
Ok, the slugification would help
from graphqlite.
👍
from graphqlite.
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)
- Empty request body parsing error for automatic persisted queries HOT 14
- prefetchMethod does not work HOT 12
- Arguments description in schema HOT 3
- Undocumented Error or posible dead code HOT 3
- ExtendType and Type with class argument don't work
- Defining fields in type by trait from different namespace ends with error for relative type declarations HOT 2
- Weird behaviour around __call HOT 1
- Cannot use custom naming on an Input type that's also a regular Type HOT 3
- How to debug errors? HOT 2
- Bizarre `Cannot query field "settings" on type "...".` error HOT 3
- Security attribute on extended type HOT 5
- Add support of types from vendor packages HOT 9
- GraphQLite attempts to load non-class files, resulting in weird errors HOT 18
- Implement a developer friendly caching for larger projects HOT 5
- Time to drop annotations HOT 1
- Example on the index page HOT 17
- [Error handling] Category missing in error response HOT 3
- AbstractEntity and input HOT 5
- Doctrine and GraphQLite HOT 1
- Huge performance regression caused by new class finder package 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 graphqlite.