-
Notifications
You must be signed in to change notification settings - Fork 4
chore: @value snippets #65
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 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
adfb8dc
@value snippets added
Jayaramv99 b9d44c6
@value main Snippets added
Jayaramv99 0c89aed
@value desc modified
Jayaramv99 ca6f5c4
@value conversion test case modified
Jayaramv99 5509985
resolved review comments
Jayaramv99 1345f30
resolved review comments
Jayaramv99 d91af87
resolved review comments
Jayaramv99 e51dfe1
resolved review comments
Jayaramv99 9f7f3ff
resolved review comments
Jayaramv99 d13bc6d
resolved review comments
Jayaramv99 a804d3c
Merge branch 'main' into jayaram/value-directive
Jayaramv99 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# @value | ||
|
||
The `@value` directive defines a value that can be applied in various contexts, each with specific behaviors. | ||
- When applied to a field, selecting the field will return the specified value. | ||
|
||
If no arguments are provided (`@value`) then the value is `null`. | ||
|
||
View the [documentation](https://www.ibm.com/docs/en/api-connect/ace/saas?topic=directives-directive-value) on the custom directive `@value`. | ||
|
||
## Snippets | ||
|
||
- [arguments](arguments) shows how sets the element to a constant value | ||
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,43 @@ | ||
# A `@value` directive defines a value that can be applied in various contexts | ||
Jayaramv99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# To establish a constant value within a type or query, we can utilize this directive. | ||
Jayaramv99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# If no arguments are provided (@value) then the value is null. | ||
|
||
type Customer { | ||
name: String! | ||
city: String! | ||
} | ||
|
||
# To establish a constant value for the state, utilize `@value` and provide the constant value. | ||
extend type Customer{ | ||
state:String @value(const:"Florida") | ||
} | ||
|
||
|
||
type Query { | ||
emptyCustomer(id: ID): Customer @value # return null value | ||
Jayaramv99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
customer(id: ID): Customer # set the default value | ||
Jayaramv99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@value( | ||
script: { | ||
src: """ | ||
Object({name:'John Doe',city:'Miami'}) | ||
""" | ||
language: ECMASCRIPT | ||
} | ||
) | ||
# To pass a constant value directly in a query and return the result | ||
Jayaramv99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pi:Float! @value(const:3.14159) | ||
|
||
# To sum a and b using the @value directive within src in jsonata, | ||
Jayaramv99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
sum(a: Int!, b: Int!): Int! @value(script: {src: "a+b", language: JSONATA}) | ||
|
||
# To concatenate strings using @value in jsonata | ||
Jayaramv99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
concat(a: String, b: String): String | ||
@value( | ||
script: { | ||
src: """ | ||
$join([a,b], "-") | ||
""" | ||
language: JSONATA | ||
} | ||
) | ||
} |
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,38 @@ | ||
const { | ||
deployAndRun, | ||
stepzen, | ||
getTestDescription, | ||
} = require("../../../tests/gqltest.js"); | ||
|
||
testDescription = getTestDescription("snippets", __dirname); | ||
|
||
describe(testDescription, function () { | ||
const tests = [ | ||
{ label: "emptyCustomer with return null", | ||
query: '{emptyCustomer(id:1){name city }}', | ||
expected: {emptyCustomer: null}, | ||
}, | ||
{ label: "customer(1)", | ||
query: '{customer(id:1){name city }}', | ||
expected: {customer: {name:'John Doe',city:'Miami'}}, | ||
}, | ||
{ label: "customer(2) with pass default state value", | ||
query: '{customer(id:2){name city state }}', | ||
expected: {customer: {name:'John Doe',city:'Miami',state:"Florida"}}, | ||
}, | ||
{ label: "return pi const value 3.14159", | ||
query: '{pi}', | ||
expected: {pi:3.14159}, | ||
}, | ||
{ label: "return sum of two input using @value with script-json", | ||
query: '{sum(a: 10, b: 10)}', | ||
expected: {sum: 20}, | ||
}, | ||
{ label: "concat string", | ||
query: '{concat(a: "Steve",b:"Jobs" )}', | ||
expected: {concat: 'Steve-Jobs'}, | ||
}, | ||
] | ||
return deployAndRun(__dirname, tests, stepzen.admin); | ||
}); | ||
|
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.
Uh oh!
There was an error while loading. Please reload this page.