Giter Site home page Giter Site logo

Comments (12)

fbartho avatar fbartho commented on September 6, 2024

@GeertWille If you can submit a test for us to explain what you mean, I’d love to take a look!

from apollo-link-rest.

HeyHugo avatar HeyHugo commented on September 6, 2024

I think I've encountered thing as well. Heres a small example:

gql`
  query FilterItems(
    $priceMin: Int
    $priceMax: Int
  ) {
    filterItems(
      priceMin: $priceMin
      priceMax: $priceMax
    )
      @rest(
        type: "Item"
        path: "filter?priceMax=:priceMax&priceMin=:priceMin"
      ) {
      id
      name
      price
    }
  }
`

So here I may or may not have priceMax and priceMin, but if I don't have them I will get the:
Missing params to run query error...

Maybe there is an easy way to dynamically build up the query string somehow?

from apollo-link-rest.

fbartho avatar fbartho commented on September 6, 2024

does that still happen if you pass null for that parameter to the variables hash?

from apollo-link-rest.

HeyHugo avatar HeyHugo commented on September 6, 2024

Yes confirmed now that it still happens with null values

from apollo-link-rest.

fbartho avatar fbartho commented on September 6, 2024

@HeyHugo What do you expect the path: to be turned into?
filter?priceMax=undefined&priceMin=5

If that's not what you expect, I don't think we can make the path omit undefined chunks and it would be clunky to provide a function to map the path.

from apollo-link-rest.

HeyHugo avatar HeyHugo commented on September 6, 2024

Hmm maybe this is crazy bad idea :)

..but what if instead of having the path inside the rest graphql directive the API was to provide a function somwhere taking the variables (and props?) as arguments and returning the path.

from apollo-link-rest.

fbartho avatar fbartho commented on September 6, 2024

I thought about that! -- We even have an example of the bodyBuilder as a function -- the problem is that a fundamental feature of apollo-link-rest is that you can @rest(path: "filter…") on any level of any GraphQL query. The result is that you'd have to provide your pathMapper-function as a variable that you pass in to all the queries that use @rest(path: "filter…") -- that would be really clunky. :(

from apollo-link-rest.

fbartho avatar fbartho commented on September 6, 2024

We could maybe have a registry of dynamic path-mappers at the RestLink-level, and have your @rest directive state the path-mapper-identifier to use, and pass the current variables in to the function, maybe?

from apollo-link-rest.

HeyHugo avatar HeyHugo commented on September 6, 2024

Cool, yes that would cover my use case at least πŸ‘

from apollo-link-rest.

fbartho avatar fbartho commented on September 6, 2024

@HeyHugo -- I recommend opening a new GitHub issue to track that feature idea. If you have time & the inclination to help improve apollo-link-rest if you wanted to implement this, I could help you get it reviewed. -- Like I said, most of what you'll need to do is like the bodyBuilder

from apollo-link-rest.

HeyHugo avatar HeyHugo commented on September 6, 2024

Ok, I'll make an attempt at this.

Would be my first TypeScript code ever, so I'm expecting some bumps 😬

from apollo-link-rest.

GeertWille avatar GeertWille commented on September 6, 2024

looks good to me! Thanks for the very fast response and PR πŸ‘

from apollo-link-rest.

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.