Overview
Starting to think more with what all we can do with the power of Lambda!! Wohoo!! Ummm… maybe.
Concept: With lambda Field resolver we can do just about anything we want inside a javascript resolver when that field is called and return whatever type we define in our schema. one of the available arguments from the props in the resolving function is args
. So in theory, we can pass args
from a query to a resolving lambda script. Let’s try it… Nope, Doesn’t Work.
I expect that either the args
would equal the input from the field or the input from the root query. What I found is that args
is an empty object {}
no matter how I try to pass args
.
I believe I am seeing 2 issues (args not passed, JWT not passed). This topic is only for the first issue of no args. I will open another based on this for JWT not being passed.
Steps to Reproduce:
Schema:
type Contact {
id: ID
name: String
fromAPI: String
syncAPI(input: String): String @lambda
}
Lambda:
async function syncAPI(props) {
return JSON.stringify(props)
}
self.addGraphQLResolvers({
"Contact.syncAPI": syncAPI
})
Add a User
mutation {
addContact(input: [{
name: "Foo"
}]) {
numUids
contact {
id
name
fromAPI
}
}
}
results:
{
"data": {
"addContact": {
"numUids": 1,
"contact": [
{
"id": "0x4",
"name": "Foo",
"fromAPI": null
}
]
}
},
"extensions": {
"touched_uids": 7,
"tracing": {
"version": 1,
"startTime": "2021-01-14T18:57:36.504098158Z",
"endTime": "2021-01-14T18:57:36.509134348Z",
"duration": 5036194,
"execution": {
"resolvers": [
{
"path": [
"addContact"
],
"parentType": "Mutation",
"fieldName": "addContact",
"returnType": "AddContactPayload",
"startOffset": 115110,
"duration": 4894812,
"dgraph": [
{
"label": "mutation",
"startOffset": 176368,
"duration": 2436394
},
{
"label": "query",
"startOffset": 3641973,
"duration": 1339675
}
]
}
]
}
}
}
}
Query for Contacts
query {
queryContact(first: 10) {
id
name
fromAPI
syncAPI(input: "bar")
}
}
results
{
"data": {
"queryContact": [
{
"id": "0x4",
"name": "Foo",
"fromAPI": null,
"syncAPI": "{\"isTrusted\":false,\"parents\":[{\"id\":\"0x4\",\"name\":\"Foo\"}],\"args\":{},\"dql\":{},\"parent\":{\"id\":\"0x4\",\"name\":\"Foo\"}}"
}
]
},
"extensions": {
"touched_uids": 3,
"tracing": {
"version": 1,
"startTime": "2021-01-14T19:10:03.827410948Z",
"endTime": "2021-01-14T19:10:03.845784571Z",
"duration": 18373658,
"execution": {
"resolvers": [
{
"path": [
"queryContact"
],
"parentType": "Query",
"fieldName": "queryContact",
"returnType": "[Contact]",
"startOffset": 89797,
"duration": 18237001,
"dgraph": [
{
"label": "query",
"startOffset": 179257,
"duration": 1563767
}
]
}
]
}
}
}
}
Here is this: @pbassham