Skip to content

Commit 9f7f3ff

Browse files
committed
resolved review comments
1 parent e51dfe1 commit 9f7f3ff

File tree

7 files changed

+125
-82
lines changed

7 files changed

+125
-82
lines changed

value/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ View the [documentation](https://www.ibm.com/docs/en/api-connect/ace/saas?topic=
99

1010
## Snippets
1111

12-
- [arguments](arguments) shows how sets the element to a constant value
12+
- [constants](constants) shows how sets the element to a constant value

value/arguments/api.graphql

-43
This file was deleted.

value/arguments/tests/Test.js

-38
This file was deleted.

value/constants/api.graphql

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# A `@value` directive defines a value that can be applied in various contexts
2+
# To establish a constant value for a field, we can utilize this directive.
3+
# If no arguments are provided (@value) then the value is null.
4+
5+
type Customer {
6+
name: String!
7+
city: String!
8+
}
9+
10+
# To establish a constant value for the state, utilize `@value` and provide the constant value.
11+
# xid will always resolve to null.
12+
# joinDate returns a constant value using the @value annotation.
13+
# createdDate returns a constant value using the @value annotation.
14+
extend type Customer{
15+
state:String @value(const:"Florida")
16+
xid:ID @value
17+
joinDate: Date @value(const: "2024-02-24")
18+
createdDate: DateTime @value(const: "2024-02-24T07:20:50.52Z")
19+
}
20+
21+
22+
type Query {
23+
# return null value
24+
emptyCustomer(id: ID): Customer
25+
26+
# set the default value
27+
customer(id: ID): Customer
28+
@value(
29+
script: {
30+
src: """
31+
Object({name:'John Doe',city:'Miami'})
32+
"""
33+
language: ECMASCRIPT
34+
}
35+
)
36+
37+
38+
# To concatenate strings using @value in jsonata
39+
concat(a: String, b: String): String
40+
@value(
41+
script: {
42+
src: """
43+
$join([a,b], "-")
44+
"""
45+
language: JSONATA
46+
}
47+
)
48+
}
49+
50+
# JSON scalars with @value
51+
extend type Query {
52+
json_string: JSON @value(const: "goodbye")
53+
json_list: JSON @value(const: [2, "hi"])
54+
}
55+
56+
# Constant scalar values
57+
type Query {
58+
returnBoolean: Boolean @value(const: true)
59+
integer: Int @value(const: 94)
60+
float: Float @value(const: 241.8)
61+
}
62+
File renamed without changes.

value/constants/tests/Test.js

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
const {
2+
deployAndRun,
3+
stepzen,
4+
getTestDescription,
5+
} = require("../../../tests/gqltest.js");
6+
7+
testDescription = getTestDescription("snippets", __dirname);
8+
9+
describe(testDescription, function () {
10+
const tests = [
11+
{ label: "emptyCustomer with return null",
12+
query: '{emptyCustomer(id:1){name city }}',
13+
expected: {emptyCustomer: null},
14+
},
15+
{ label: "customer(1)",
16+
query: '{customer(id:1){name city }}',
17+
expected: {customer: {name:'John Doe',city:'Miami'}},
18+
},
19+
{ label: "customer(2) with pass default state value",
20+
query: '{customer(id:2){name city state }}',
21+
expected: {customer: {name:'John Doe',city:'Miami',state:"Florida"}},
22+
},
23+
{ label: "customer(3) xid returns null value",
24+
query: '{customer(id:2){name city state xid }}',
25+
expected: {customer: {name:'John Doe',city:'Miami',state:"Florida",xid:null}},
26+
},
27+
{ label: "customer(4) joinDate returns const value",
28+
query: '{customer(id:2){name city joinDate }}',
29+
expected: {customer: {name:'John Doe',city:'Miami',joinDate:'2024-02-24'}},
30+
},
31+
{ label: "customer(5) createdDate returns const value",
32+
query: '{customer(id:2){name city createdDate }}',
33+
expected: {customer: {name:'John Doe',city:'Miami',createdDate:'2024-02-24T07:20:50.52Z'}},
34+
},
35+
{ label: "concat string",
36+
query: '{concat(a: "Steve",b:"Jobs" )}',
37+
expected: {concat: 'Steve-Jobs'},
38+
},
39+
{ label: "JSON scalars return json_string",
40+
query: '{json_string}',
41+
expected: {"json_string": "goodbye"},
42+
},
43+
{ label: "JSON scalars return json_list",
44+
query: '{json_list}',
45+
expected: {"json_list": [2,"hi"]},
46+
},
47+
{ label: "return const true boolean value ",
48+
query: '{returnBoolean}',
49+
expected: {"returnBoolean": true},
50+
},
51+
{ label: "return const integer value ",
52+
query: '{integer}',
53+
expected: {"integer": 94},
54+
},
55+
{ label: "return const float value ",
56+
query: '{float}',
57+
expected: {"float": 241.8},
58+
},
59+
]
60+
return deployAndRun(__dirname, tests, stepzen.admin);
61+
});
62+

0 commit comments

Comments
 (0)