max
11/03/2017, 4:21 PMYou are referencing a node that does not exist.
It's almost like it's too quick and the node doesn't yet exist. As way of checking I completed my mutation in the playground and it worked.nilan
11/03/2017, 4:27 PMmax
11/03/2017, 4:34 PMnilan
11/03/2017, 4:35 PMmax
11/03/2017, 4:35 PMnilan
11/03/2017, 4:36 PMmax
11/03/2017, 4:36 PMsubscription {
Document(filter: {
mutation_in: [CREATED]
}) {
updatedFields
node {
id
name
owner {
id
name
}
}
}
}
'use latest'
// on subscription to CREATED document
const { fromEvent } = require('graphcool-lib')
// replace with your root token and project id
const rootToken = process.env['ROOT_TOKEN'];
const serviceId = process.env['SERVICE_ID'];
export default (event) => {
// augment event context with project id and root token
event.context = {
graphcool: {
rootToken,
serviceId
}
}
// create simple api client
const api = fromEvent(event).api('simple/v1');
// graphQL mutation
const createDocumentAccess = `
mutation createDocumentAccess(
$access: DocumentAccessType!
$documentId: ID!
$userId: ID!
) {
createDocumentAccess(
access: $access
documentId: $documentId
userId: $userId
) {
id
access
document {
id
name
}
user {
id
name
}
}
}
`;
const variables = {
access: 'ADMIN',
documentId: event.data.Document.node.id,
userId: event.data.Document.node.owner.id
}
// Return a Promise to wait for the mutation to complete
return new Promise((resolve,reject) => {
api.request(createDocumentAccess, variables)
.then(data => resolve({ data: event.data }))
.catch(err => resolve({ error: err}))
})
}
nilan
11/03/2017, 4:43 PMmax
11/03/2017, 4:45 PMsetTimeout( () => {
return new Promise((resolve,reject) => {
api.request(createFundAccess, variables)
.then(data => resolve({ data: event.data }))
.catch(err => resolve({ error: err}))
})
}, 1000);
angly
11/03/2017, 5:06 PM'use latest'
, btw?nilan
11/03/2017, 5:07 PMangly
11/03/2017, 5:11 PM'use strict'
or 'use asm'
, it's just that I can't google anything about it.nilan
11/03/2017, 5:11 PMangly
11/03/2017, 5:23 PM