-
Notifications
You must be signed in to change notification settings - Fork 4
chore: example for setters argument for @rest directive #68
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f45e618
chore: example for setters argument for @rest directive
asararatnakar c3552b2
prettify
asararatnakar 10e1c20
removed the rest call and simulated JSON response as suggested
asararatnakar a2911a4
update comments
asararatnakar 72a1278
minor edits:
asararatnakar a3e0f07
Merge branch 'main' into add_setters
asararatnakar 12ed847
address comments
asararatnakar fe75e1a
change names to look better
asararatnakar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# We first transform the JSON result object from REST API the Graphql structure | ||
# and then map the JSON response to the fields corresponding to the GraphQL type. | ||
|
||
type Customer { | ||
cId: ID | ||
cName: String | ||
cAddress: Address | ||
} | ||
type Address { | ||
city: String | ||
countryRegion: String | ||
stateProvince: String | ||
street: String | ||
postalCode: String | ||
} | ||
|
||
type Query { | ||
customer(id: ID): [Customer] | ||
@rest( | ||
endpoint: "https://json2api-customers-zlwadjbovq-uc.a.run.app/customers?q=id+eq+$id;" | ||
# The jq expression transform each element of the array. | ||
# StepZen takes care of calling jq for each element. | ||
transforms: [ | ||
{ | ||
pathpattern: [] | ||
editor: """ | ||
jq:.[]|{id,name,cAddress:{street, city, stateProvince, countryRegion}} | ||
""" | ||
} | ||
] | ||
# mapping from JSON response values to the fields of the GraphQL result. | ||
setters: [{ field: "cId", path: "id" }, { field: "cName", path: "name" }] | ||
) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
schema @sdl(files: ["api.graphql"]) { | ||
query: Query | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"endpoint": "api/miscellaneous" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const { | ||
deployAndRun, | ||
getTestDescription, | ||
} = require("../../../tests/gqltest.js"); | ||
|
||
testDescription = getTestDescription("snippets", __dirname); | ||
|
||
describe(testDescription, function () { | ||
const tests = []; | ||
return deployAndRun(__dirname, tests); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, can we have the GraphQL object have the natural names and the response have "weird" names