GraphQLBundle icon indicating copy to clipboard operation
GraphQLBundle copied to clipboard

[Annotation] Add option to @Provider to attach to different types

Open akomm opened this issue 7 years ago • 13 comments

Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? no
Version/Branch ^0.12

Currently you can only provide fields to root types via @Provider and @Mutation/@Query on those root types. AFAIK this is also limited to the default schema root types.

I realized this is also needed for non root types, when you have for example two fields connecting something and this logic requires some different services, I have currently to create a type (service) with two dependencies for different purposes.

There are maybe different ways of doing it. One could be: Instead of @Query and @Mutation, give @Provider an option like type=Query, which would make the annotated field, etc. being "injected" into the type Query. This would also allow it to work with any type and independent of schema (single, multi).

akomm avatar Jul 18 '19 09:07 akomm

Hi @akomm Actually, their is an option targetType on @Query to target a different type for queries. See Query annotation

Vincz avatar Jul 18 '19 09:07 Vincz

@Vincz You are right, the I currently have the exact same page open, the description initially confused it as it states it does use the Query from definitions config. :)

akomm avatar Jul 18 '19 09:07 akomm

The idea of @Provider was to be able to tell the parser that this specific class contains queries and/or mutations and be able to "group" them (with a prefix, or with @Access). I don't know if I picked the best option to do so. But we could add a queriesTarget on the @Provider to automatically add the targetType on queries contained in the Provider. I don't know...

Vincz avatar Jul 18 '19 09:07 Vincz

It is still a bit different to my proposal, as it is then on per-field base not @Provider but might be enough, can not tell yet what is better. The major issue was the (wrongly assumed) lack of ability to enhance other types.

I think the docs should then be something like: By default, the resulting field is added to the main Query type (define in configuration at key overblog_graphql.definitions.schema.query) instead of: The resulting field is added to the main Mutation type (define in configuration at key overblog_graphql.definitions.schema.query).

akomm avatar Jul 18 '19 09:07 akomm

~~Oh and missing it on Mutation too. Going to add it there too. :)~~ @Mutation does not have this option actually.

akomm avatar Jul 18 '19 09:07 akomm

That is what I was about to say ^^

Vincz avatar Jul 18 '19 09:07 Vincz

@Vincz its not exactly the proposed feature and mutation does have the field, but I mostly need this on query types, so it should be no problem. I close it and should there be any issue I did not notice yet, I reopen it.

akomm avatar Jul 18 '19 10:07 akomm

@Vincz @akomm Hello, is there any reason why there is no targetType option for the Mutation case? For example I want to implement two different schema types - one with access control and one without. This definition is exactly what I need but I can have only one mutation type because I can't set any mutations in the bar one and an error is triggered. All mutations that I add with annotations are being assigned to the default mutation.

schema:
   default:
      query: Query
      mutation: Mutation
   bar:
      query: AuthorizedQuery
      mutation: AuthorizedMutation

with access control

access_control:
         - { path: ^/graphql/bar, roles: ROLE_USER }

I get the following error:

The path "overblog_graphql_types.AuthorizedMutation._object_config.fields" should have at least 1 element(s) defined.

snaksa avatar Jan 18 '20 20:01 snaksa

@snaksa Hi ! You are right, I didn't think about multiple schemas when I implemented this. So, it would also make sense to handle targetType for mutations too. Feel free to PR, or if you can't, I'll try to check this by the end of the week.

Vincz avatar Jan 20 '20 13:01 Vincz

I actually noticed this too, but then realized: "oh you don't nest mutation, so there will be only 1 mutation type". But @snaksa is right, different schemas...

akomm avatar Jan 20 '20 14:01 akomm

Hi! As we discussed I added a PR that implements this :)

snaksa avatar Jan 20 '20 21:01 snaksa

Hey @snaksa ! Thank you for this PR ! It's a really good start. I did a little review and hope it is clear otherwise I'll be glad to help.

Vincz avatar Jan 20 '20 22:01 Vincz

Done in #710 & #725

Vincz avatar Aug 13 '20 08:08 Vincz