By using AWS re:Post, you agree to the Terms of Use
/Mutation through API fails, but works from web portal/

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.


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 createLink($organizationID: ID, $schoolID: ID){
	  	type: School
		organizationLinkOrganizationId: $organizationID
		organizationLinkSchoolId: $schoolID
	  })  {    id  }

API Call method:

const resp = await fetch(graphqlApi, {
		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: '',
     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

1 Answers

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"

answered 3 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions