Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mutation #213

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Mutation #213

wants to merge 10 commits into from

Conversation

miklemv
Copy link
Contributor

@miklemv miklemv commented Nov 9, 2019

  1. Control of access rights for reading entities.
    The @GraphQLReadEntityForRole annotation indicates which roles are available for reading. If this annotation is not available to everyone. When creating GraphQLJpaSchemaBuilder, you can set predicateRole to which the array of roles is passed and the predicate should return whether the current user has any of the transferred roles.

  2. Mutations
    there are 4 operations
    insert
    update
    merge
    delete

4 mutations are prepared for each entity
insertEntity - insertion of the specified entity, entities specified in the parameters are searched in the database
updateEntity - update record by id, entities specified in the parameters are searched in the database
mergeEntity - full merge, inserts / updates all specified parameters
deleteEntity - delete by id

to process queries in the system graphQL types are created with the prefix specified through suffixInputObjectType (by default, Input)

example queries in MutationTests

  1. Rights to operations
    The @GraphQLWriteEntityList and @GraphQLWriteEntityForRole annotation indicates which roles what actions are available. If this annotation is not specified and an access predicate is specified, an exception is raised. When creating GraphQLJpaSchemaBuilderWithMutation, you can set predicateRole to which the array of roles is passed and the predicate should return whether the current user has any of the transferred roles.

This code is still poorly tested.

@codecov
Copy link

codecov bot commented Nov 9, 2019

Codecov Report

Merging #213 into master will increase coverage by 0.2%.
The diff coverage is 74.54%.

Impacted file tree graph

@@             Coverage Diff             @@
##             master     #213     +/-   ##
===========================================
+ Coverage     74.05%   74.25%   +0.2%     
- Complexity      882     1006    +124     
===========================================
  Files            50       63     +13     
  Lines          3754     4296    +542     
  Branches        628      709     +81     
===========================================
+ Hits           2780     3190    +410     
- Misses          696      778     +82     
- Partials        278      328     +50
Impacted Files Coverage Δ Complexity Δ
...es/graphql/jpa/query/schema/model/book/Author.java 0% <ø> (ø) 0 <0> (ø) ⬇️
...ures/graphql/jpa/query/schema/model/book/Book.java 0% <ø> (ø) 0 <0> (ø) ⬇️
...phql/jpa/query/schema/ExceptionGraphQLRuntime.java 0% <0%> (ø) 0 <0> (?)
...s/graphql/jpa/query/schema/impl/FetcherParams.java 100% <100%> (ø) 3 <3> (?)
...ry/schema/impl/GraphQLJpaOneToManyDataFetcher.java 74.19% <100%> (+0.42%) 11 <4> (ø) ⬇️
...s/graphql/jpa/query/schema/impl/MapEntityType.java 100% <100%> (ø) 4 <4> (?)
...query/schema/impl/GraphQLJpaSimpleDataFetcher.java 91.66% <100%> (+0.36%) 7 <3> (ø) ⬇️
...a/query/mutations/annotation/GraphQLWriteType.java 100% <100%> (ø) 1 <1> (?)
...jpa/query/schema/impl/GraphQLJpaSchemaBuilder.java 91.7% <100%> (+0.08%) 120 <3> (+2) ⬆️
...a/query/schema/impl/GraphQLJpaBaseDataFetcher.java 76.49% <50%> (ø) 172 <0> (?)
... and 25 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0151eec...2322eaf. Read the comment docs.

@markxj
Copy link

markxj commented Mar 18, 2020

Is there any update on this? Or is there another way to do mutations?

@markxj
Copy link

markxj commented Apr 6, 2020

@miklemv @igdianov

Is this going to get merged at all? I'd love to adopt graphql-jpa-query but I can't without mutation support

@miklemv
Copy link
Contributor Author

miklemv commented Apr 13, 2020

I don’t know other ways to apply mutations. I think the use of mutations will be useful, but so far this is a crude solution. If necessary, I will try to support the revision.

@federico-s
Copy link

federico-s commented Apr 22, 2020

Any news? I'd like to use mutations with graphql-jpa-query.
Is there a way to do mutations "normally" using com.coxautodev.graphql.tools.GraphQLMutationResolver ?

@miklemv
Copy link
Contributor Author

miklemv commented Apr 22, 2020

Any news? I'd like to use mutations with graphql-jpa-query.
Is there a way to do mutations "normally" using com.coxautodev.graphql.tools.GraphQLMutationResolver ?

Yes. You can do any migrations using the standard base class.

@miklemv
Copy link
Contributor Author

miklemv commented Apr 22, 2020

@igdianov

will there be an opportunity to do merge? If yes, I can update the branch.

@federico-s
Copy link

Any news? I'd like to use mutations with graphql-jpa-query.
Is there a way to do mutations "normally" using com.coxautodev.graphql.tools.GraphQLMutationResolver ?

Yes. You can do any migrations using the standard base class.

I got the following error:

{
  "errors": [
    {
      "message": "Schema is not configured for mutations.",
      "locations": [
        {
          "line": 1,
          "column": 1
        }
      ],
      "extensions": {
        "classification": "OperationNotSupported"
      }
    }
  ]
}

I added the file src/main/resources/graphql/subscriber.graphqls with the following content:

type Mutation {
    addSubscriber(name: String!, endpoint: String!) : Subscriber
}

The Subscriber type is auto-generated from the schema. Am i missing something?
I'm calling the mutation with:

mutation {
  addSubscriber(name:"MutationTest", endpoint:"http://test.com") {
    name
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants