Code Monkey home page Code Monkey logo

Comments (6)

danielkcz avatar danielkcz commented on July 26, 2024

I am bit confused here. I mean the selection set is already implemented and works, you can do binding.query.addresses({}, '{ id }'). It's possible I've misunderstood something and this works differently, but that would a breaking change.

An addition of delegateQuery is somewhat interesting, but in my opinion not exactly essential. Honestly, I did not even know there are some aliases in graphql :)

I am coming from a bit different direction regarding subscriptions (see prisma-labs/prisma-binding#78 (comment)). If I am not mistaken, there is no solution for that in this proposal. In case that wasn't the intention, I apologize :)

from graphql-binding.

timsuchanek avatar timsuchanek commented on July 26, 2024

Thanks for the answer @FredyC ! It would indeed be a breaking change, which we would of course be reflected in the semver version.
I'm answering in that issue separate, what I think you need is the opposite of makeSubInfo, which is embedding an info in a parent context

from graphql-binding.

gcangussu avatar gcangussu commented on July 26, 2024

Thank you for your work @timsuchanek. Regarding the two problems:

  1. Field not selected

In the case that there is no fragment (e.g. makeSubInfo(info, 'subfield')), couldn't we return null or throw an error that could be handled by the programmer? There is also the possibility of returning an info object with an empty selection ('{ }').

And in the case that there is a fragment (e.g. makeSubInfo(info, 'subfield', '{ id }')) it would make sense for me if it returns an info for that subfield and selection fragment (subfield { id }).

  1. Aliases

I couldn't test with a field that returns an array, but my implementation of makeSubInfo is working with aliases and fields that return an object. I did a fast test here and

mutation {
  login(email: "[email protected]", password: "123456789") {
    gabrielToken: token
    names: user(alias: "names") { name, company { name } }
    ids: user(alias: "ids") { id, company { id } }
  }
}

Gave me

{
  "data": {
    "login": {
      "gabrielToken": "eyJhbGciO...hXa2Uhg",
      "names": {
        "name": "Gabriel",
        "company": {
          "name": "ACME"
        }
      },
      "ids": {
        "id": "cjftyusg900080827nwt39wds",
        "company": {
          "id": "cjftyusi300090827ub3s66m6"
        }
      }
    }
  }
}

But the object returned by my resolver wasn't using the aliases it was in the shape of

{
  token: '',
  user: {
    id: '',
    name: '',
    company: {
      id: '',
      name: '',
    },
  },
}

graphql-yoga probably did the work of extracting the right properties and mounting the correct response. I wounder how it behaves with your example, does it throw an error or return the full array for both aliases?

Now, about your solution, I think it would work great. We would just change this:

const addresses = await ctx.db.query.addresses({where: {userId}}, makeSubInfo(info, 'addresses'))
return {
  id: userId,
  addresses
}

To this

const addresses = await ctx.db.delegateQuery.addresses({where: {userId}}, info)
return {
  id: userId,
  ...addresses
}

Did I get it right?

from graphql-binding.

timsuchanek avatar timsuchanek commented on July 26, 2024

@gcangussu thanks for your answer. Yes you got it exactly right. Interesting, that it has been resolved properly in your use case, I will try to reproduce that. In my case both aliases got the same payload back, even if the args differed.

from graphql-binding.

ntziolis avatar ntziolis commented on July 26, 2024

@timsuchanek I found a minor bug (2 lines) in the makeSubInfo method that prevented using it for sub field selection see pull request here: #149

from graphql-binding.

Urigo avatar Urigo commented on July 26, 2024

Thank you for reporting.

In the last few months, since the transition of many libraries under The Guild's leadership, We've reviewed and released many improvements and versions to graphql-cli, graphql-config and graphql-import.

We've reviewed graphql-binding, had many meetings with current users and engaged the community also through the roadmap issue.

What we've found is that the new GraphQL Mesh library is covering not only all the current capabilities of GraphQL Binding, but also the future ideas that were introduced in the original GraphQL Binding blog post and haven't come to life yet.

And the best thing - GraphQL Mesh gives you all those capabilities, even if your source is not a GraphQL service at all!
it can be GraphQL, OpenAPI/Swagger, gRPC, SQL or any other source!
And of course you can even merge all those sources into a single SDK.

Just like GraphQL Binding, you get a fully typed SDK (thanks to the protocols SDKs and the GraphQL Code Generator), but from any source, and that SDK can run anywhere, as a connector or as a full blown gateway.
And you can share your own "Mesh Modules" (which you would probably call "your own binding") and our community already created many of those!
Also, we decided to simply expose regular GraphQL, so you can choose how to consume it using all the awesome fluent client SDKs out there.

If you think that we've missed anything from GraphQL Binding that is not supported in a better way in GraphQL Mesh, please let us know!


In the context of that particular issue - GraphQL Mesh uses the new schema stitching introduced in GraphQL Tools v6 and together with the transform API should be able to cover optimizations like that.

But I might be missing the purpose here so, please feel free to open a new issue on the GraphQL Mesh repo.

We're looking forward for your feedback of how we can make your experience even better!

from graphql-binding.

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.