question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support finding queries and mutations in the same class

See original GitHub issue

Is your feature request related to a problem? Please describe. I have a traditional java/kotlin service (that handles both mutations and queries) and I’d like to expose most of it’s methods without repeating myself too much, while adding a necessary layer for authorization checks.

Currently, I have to create two classes: one that exposes my existing service’s queries and another that exposes the mutations.

For example:

    class UserService {
        val users = mutableMapOf<Int, String>()
        fun getUser(id: Int) = users[id]
        fun createUser(name: String) {
            val id = users.keys.max() ?: 0 + 1
            users[id] = name
        }
    }

    class UserQueries(private val userService: UserService) {
        fun getUser(id: Int) = userService.getUser(id)
    }
    
    class UserMutations(private val userService: UserService) {
        fun createUser(name: String) = userService.createUser(name)
    }

This gets tedious when user has a lot of fields

Describe the solution you’d like I’m not sure, but I think this might be easier if there was a way to pass lists of functions or function references to SchemaGenerator or QueryBuilder instead of having to define a class. Your library would allow users to compose a graphql api from functions and existing services.

Describe alternatives you’ve considered You are probably aware of https://github.com/pgutkowski/KGraphQL. That project seems to have lost some steam, but has some cool characteristics in that it allows composing the graphql api in a direct, simple manner. Unfortunately, there’s a lot of boilerplate involved.

Additional context Add any other context or screenshots about the feature request here.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
pabl0rgcommented, Mar 22, 2019

🤦‍♂️ thanks!

0reactions
pabl0rgcommented, Mar 26, 2019

This will at least give some separation of legacy code and code that is new for GraphQL

I was hoping the MovieLensQueries and MovieLensMutations classes could be that layer and not require much boilerplate. (We like having something like the MovieLensService for consumption by other kotlin/java modules in the same process. Monoliths are fast and easy to maintain)

I’ll try another approach. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Queries and Mutations - GraphQL
A mutation can contain multiple fields, just like a query. There's one important distinction between queries and mutations, other than the name: While...
Read more >
GraphQL Mutation vs Query – When to use a GraphQL Mutation
Mutations look very similar to queries. If you'll recall, the general structure of a GraphQL operation looks like this.
Read more >
Run Queries and Mutations - AWS AppSync
In the AWS AppSync console choose the Queries tab on the left hand side. The pane on the right side enables you to...
Read more >
Avoiding too many query types and mutations representing ...
Does anyone know a way to represent different query and mutation types in a single class? Or even, to create a unique class...
Read more >
Supporting opt-in nested mutations in GraphQL
For the standard behavior, queries and mutations are handled separately through two different root types: the QueryRoot and the MutationRoot ( ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found