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

Missing documentation for pathBuilder and using query string parameters #276

Closed
samzmann opened this issue Nov 13, 2020 · 2 comments
Closed

Comments

@samzmann
Copy link

I'm trying to query a rest endpoint and pass variables as query string, for example /api/resource?arg1=true&arg2=false... From looking at the docs I assume the recommended way is to use pathBuilder however there is no example or clear documentation of how to use it properly.

I've looked at the following issues and PRs to try to get more info:
#70
#39
#160

However I still don't get pathBuilder is supposed to be used.

Could you point me to an explanation or example of how to query endpoints that have query string parameters. I'll be happy to submit a PR to update the docs once I figure this out.

I also posted a question on SO, with more details about my particular use case.

Thanks!

@Rennzie
Copy link

Rennzie commented Nov 14, 2020

Hey @Lavielle you shouldn't need to use the pathBuilder for simple query params. You can pass your variables directly into your path like so:

 query QueryAliasAndVariableDeclerations(
    $fieldId: String!
    $startDate: String!
    $endDate: String!
  ) {
 // make sure you pass along the above variables into the query itself.
    gqlQuery(fieldId: $fieldId, startDate: $startDate, endDate: $endDate)
      @rest(
        type: "FieldSurveysDataPayload"
        path: "/api/field/{args.fieldId}?start_date={args.startDate}&end_date={args.endDate}"
        method: "GET"
      ) {
   // ... your expected response 
 }
}

I posted a more detailed response on SO

@samzmann
Copy link
Author

Thanks @Rennzie for you answer, this solves my problem. Closing the issue.

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

No branches or pull requests

2 participants