Mutation through API fails, but works from web portal
Hey! I'm trying to get some help figuring out why a mutation works in the AWS AppSync web portal, but fails when I try to use the API within one of my lambda tests.
Schema:
type OrganizationLink @model @searchable @auth(rules: [
{allow: groups, groups: ["Admin"]},
{allow: groups, groupsField: "readGroups", queries: [get, list], mutations: null},
{allow: groups, groupsField: "writeGroups" mutations: [update, delete], queries: null}
]) {
id: ID!
type: OrganizationType
school: School @connection(name: "SchoolOrganization")
district: District @connection(name: "DistrictOrganization")
organization: Organization @connection(name: "OrganizationConnection")
readGroups: [String]
writeGroups: [String]
}
Auto-Generated Schema from backend/.../schema.graphql:
...
createOrganizationLink(input: CreateOrganizationLinkInput!): OrganizationLink
...
onCreateOrganizationLink: OrganizationLink @aws_subscribe(mutations: ["createOrganizationLink"])
...
input CreateOrganizationLinkInput {
id: ID
type: OrganizationType
readGroups: [String]
writeGroups: [String]
organizationLinkSchoolId: ID
organizationLinkDistrictId: ID
organizationLinkOrganizationId: ID
}
Mutation:
mutation createLink($organizationID: ID, $schoolID: ID){
createOrganizationLink(input:{
type: School
organizationLinkOrganizationId: $organizationID
organizationLinkSchoolId: $schoolID
}) { id }
}
API Call method:
const resp = await fetch(graphqlApi, {
body,
credentials: 'include',
headers: {
accept: '*/*',
authorization: AccessToken,
'content-type': 'application/json',
},
method: 'POST',
mode: 'cors',
});
API Request Body:
{
"operationName": "createOrganizationLink",
"query": "\n\t\tmutation createLink($organizationID: ID, $schoolID: ID){\n\t\t createOrganizationLink(input:{\n\t\t \ttype: School\n\t\t\torganizationLinkOrganizationId: $organizationID\n\t\t\torganizationLinkSchoolId: $schoolID\n\t\t }) { id }\n\t}",
"variables": {
"organizationId": "5432eca5-1018-4bf1-ba60-679557ca1e3c",
"schoolId": "ed1fbead-1906-4cc8-b5b3-64b3e9995501"
}
}
Response Error:
url: 'https://XXXXXXXXXX.appsync-api.us-west-2.amazonaws.com/graphql',
status: 400,
statusText: 'Bad Request',
errorType: 'BadRequestException',
message: 'No operation matches the provided operation name createOrganizationLink.' } ] }
I don't understand how the operation isn't being found, when I am using the exact same operation in the web portal. The operation to create an organization link is clearly in the schema as well. I use this same function to do other mutations prior to this one and they work flawlessly. Any hints would be greatly appreciated...please let me know if any additional information is needed.
Edited by: markta on Apr 19, 2019 2:03 PM
Apparently the 'operationName' is looking for what I consider the "nickname" of a mutation, not the actual "name".
mutation createAndStuff{
createOrganizationLink { ... } { ... }
}
Operation name is looking for "createAndStuff" not "createOrganizationLink"
Relevant questions
How to get connection duration metric from logs for AppSync subscription?
asked 15 days agoAurora Serverless AppSync error: invalid cluster id
asked 3 years agoSmart Mutation Processing for Subscriptions
asked 3 years agoMutation through API fails, but works from web portal
asked 3 years agoThe request could not be satisfied error coming from cloudfront
asked 5 years agoTrigger AppSync subscription notification asynchronously
Accepted Answerasked 5 months agoAWS Amplify AppSync Cognito User Pool
asked 2 months agoSession not refreshing tokens
asked 2 years agoAngular access to Apigateway
asked 4 months agoIdentity permissions for a background service with Appsync
asked 3 years ago