GithubHelp home page GithubHelp logo

Comments (2)

fbartho avatar fbartho commented on May 5, 2024

Implemented via #69, #70

from apollo-link-rest.

zachdixon avatar zachdixon commented on May 5, 2024

I've looked through the pathBuilder PR and think a query string builder would still be beneficial. I'm getting into writing all my queries and ran across the thought of having to provide the pathBuilder function every time. It doesn't seem very DRY (which may not be your goal).

On the Apollo docs page, it mentions a params option for the @rest directive:

const QUERY = gql`
  query RestData($email: String!) {
    users @rest(path: '/users/email/:email', params: { email: $email }, method: 'GET', type: 'User')

I think this is outdated as I don't see anything in the code that would support this unless I'm missing it, but something similar for the query string would be nice.

query RestData($email: String!) {
    users @rest(type: "[User]", path: '/users/email', queryParams: {email: $email})
}

This would automatically create a query string based on the queryParams and append it to the path. I think I would actually prefer this in the case of multiple @rest in the same query that may not use every param such as:

query RestData($userId: ID!, $startDate: String!, $endDate: String!) {
    user @rest(type: "User", path: '/users/:userId') {
        id
        name
        reports @rest(type: "[UserReport]", path: '/users/reports', queryParams: {startDate: $startDate, endDate: $endDate})
    }
}

If I understand correctly, this would be the equivalent using pathBuilder

let getPathBuilder = url => params => `${url}?${queryString.stringify(params)}`

const query = gql`
  query RestDate($userId: ID!, $startDate: String!, $endDate: String!, $userPath: any, $reportsPath: any) {
    user (id: $id) @rest(type: "User", pathBuilder: $userPath) {
      id
      name
      reports (startDate: $startDate, endDate: $endDate) @rest(type: "[UserReport]", pathBuilder: $reportsPath)
  }
`

client.query({
  query,
  variables: {
    id: someId,
    startDate: "05-01-2018",
    endDate: "05-31-2018",
    userPath: getPathBuilder("/user"),
    reportsPath: getPathBuilder("/user/reports")
  }
});

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.