Just tested now, the function is working, but fetc...
# prisma-whats-new
m
Just tested now, the function is working, but fetch seems doesn’t
a
Fetch should work. Make sure that you return it, as you have to return a promise if you're not returning a value directly
m
even in server-side-subscription function?
a
Yes
m
will try now, thank you for response man
👍🏻 1
@agartha sad but it doesn’t work(
Copy code
Call to <https://wt-graphcool.it.auth0.com/api/run/cj8fs7n930b4z0118vz25eycg/cj92wkap5001b01orkctne8gv> failed with status 400, response body {\n  \"code\": 400,\n  \"error\": \"Error when JSON serializing the result of the JavaScript code.\",\n  \"details\": \"TypeError: Converting circular structure to JSON\",\n  \"name\": \"TypeError\",\n  \"message\": \"Converting circular structure to JSON\",\n  \"stack\": \"TypeError: Converting circular structure to JSON\\n    at Object.stringify (native)\\n    at /data/sandbox/lib/sandbox.js:827:48\\
a
What does your function look like?
m
subscription query is
Copy code
subscription {
  Style(filter: {
    mutation_in: [UPDATED]
  }) {
    updatedFields
    node {
      id
      likesCount
      _likedUsersMeta {
        count
      }
    }
  }
}
May the error reason be the same model update twice?
a
No you're not returning anything after the fetch
m
on update -> I do update
oh, seems it is a recursion
a
Yes, and your update will trigger the subscription 😄
m
oh god
how can I diff this 2 updates? I have just one scenario in my head - add extra field called “isNotUpdate” and update with this extra field. And check it in update function.
a
Well, you have 'updatedFields' in your subscription result
m
Sure
a
If you update likesCount, then updatedFields will contain likesCount
m
If the likesCount there - I will do nothing
ok
a
👍🏻 like that 😄
m
thank you for patience and helping
👍🏻 1
a
Np
m
really appreciate it! You working on graph.cool project?
you a part of team or just user
a
Just community member...
m
than thank yo twice
👍🏻 1
sad but same error (((
now my function looks like that
Copy code
Error when JSON serializing the result of the JavaScript code.\",\n  \"details\": \"TypeError: Converting circular structure to JSON\",\n  \"name\": \"TypeError\",\n  \"message\": \"Converting circular structure to JSON\",\n  \"stack\": \"TypeError: Converting circular structure to JSON\\n    at Object.stringify (native)\\n    at /data/sandbox/lib/sandbox.js:827:48\\n
a
Your mutation seems incorrect (quotes)
You're missing a
}
after likesCount
Copy code
`{"query":"mutation { updateStyle(id: \"${ styleId }\" likesCount: ${ likesCount }) { id likesCount } }"}`
m
hmm will check now
thnak you again
hardcoded it, but same error, but error gone if I changing then(data => ({ data: data })) to data => ({ data: event.data })
but when there is no error, the data is not updated
so this function does work https://hastebin.com/apahamewov.lua but likesCount still same
a
Add a console.log to check the value of data before returning it.
m
When I do this console.log(data) it throws Converting circular structure to JSON
in then((data) => …
if I pass then(data => return { data: event.data }) it throws nothing
do you think is bug?
a
No, because if you do that, you're not returning the data from the mutation. Something is going wrong executing the mutation
I think you have to JSON.stringify the body by the way
m
if I do this mutation on playground it works well
a
Yes, but the escaping of the body text of the mutation request is not right
Hold on...
m
i will try to build another on with json stringify
a
You'll better switch to graphcool-lib to make your life a lot easier, I'll share an example
m
in function side?
a
Something like this
m
wow
it works
seems the reason was
in mutation stringify
can I do import { fromEvent} from ‘graphcool-lib’ inside graphcool function?
a
Yes
Try it...
m
seems ur example doesn’t work(
Copy code
SyntaxError: Unexpected reserved word\\n    at Object.exports.runInThisContext (vm.js:53:16)\\n    at WebtaskModule.compileWebtask (/data/sandbox/lib/module.js:91:32)\\n    at Object.defaultJavascriptCompiler [as nodejsCompiler] (/data/sandbox/lib/compiler.js:124:30)\\n    at module.exports.options.nodejsCompiler.fnCallback (/data/io/4470461b449745
what can be the reason? 😕
but this works well https://hastebin.com/ohahibigor.js on fetch
a
Forgot 'use latest'
m
tatus 400, response body {\n \“code\“: 400,\n \“message\“: \“Compilation failed: Cannot find module ‘graphcool-lib’\“,\n \“error\“: \“Cannot find module ‘graphcool-lib’\“,\n \“stack\“: \“Error: Cannot find module ‘graphcool-lib’\\n at Function.Module._resolveFilename (module.js32515)\\n at Function.WebtaskModule._resolveFilename (/data/sandbox/lib/module.js2527)\\n at WebtaskModule.require (/data/sandbox/lib/module.js10139)\\n at require (/data/sandbox/lib/module.js13621)\\n at Object.<anonymous>
🙂
a
Where are you running this?
m
server-side subscription
a
That's very weird
does
const fromEvent = require('graphcool-lib').fromEvent
work?
m
the error changed
\“code\“: 400,\n \“error\“: \“Script returned an error.\“,\n \“details\“: \“Error: Variable ‘$likesCount’ cannot be non input type ‘int’. (line 2, column 42):\\n mutation($styleId: ID!, $likesCount: int) {\\n ^: {\\\“response\\\“{\\\“data\\\“null,\\\“errors\\\“[{\\\“message\\\“\\\“Variable ‘$likesCount’ cannot be non input type ‘int’. (line 2, column 42):\\\\n mutation($styleId: ID!, $likesCount: int) {\\\\n ^\\\“,\\\“locations\\\“[{\\\“line\\\“2,\\\“column\\\“42}]},{\\\“message\\\“\\\“Unknown type ‘int’. Did you mean ‘Int’? (line 2, column 42):\\\\n mutation($styleId: ID!, $likesCount: int) {\\\\n ^\\\“,\\\“locations\\\“[{\\\“line\\\“2,\\\“column\\\“:42}]}],\\\”
oh
a
oops, yeah. Int instead of int
m
🙂
parrotwave1 parrotwave2 parrotwave3 parrotwave4 parrotwave5 it works!!!
thank you again, you saved my day
you will always be a dear guest in my house
👍🏻 1
a
Well, thank you, in that case! Good luck with it!