Mutation through API fails, but works from web portal

0

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

markta
已提問 5 年前檢視次數 544 次
2 個答案
0

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"

markta
已回答 5 年前
0

I just ran across this problem too. For me, at least, it is actually a bug with the Insomnia app that appears to be a recurring problem. See this github issue for more info https://github.com/Kong/insomnia/issues/5698

The problem seems to occur when you add or change the operation name after you have already made a request. For example, if you query with this:

query MyQuery{ aSchemaDefinedQuery(param: "something") { aValue } }

it will work repeatedly as many times as you want. However, if you change or remove "MyQuery" is will start failing with an error like

{
  "errors": [
    {
      "errorType": "BadRequestException",
      "message": "No operation matches the provided operation name MyQ."
    }
  ] 
}

If you reselect the operation in Insomnia (at the top left of the GraphQL tab) it will start working again.

Brian
已回答 8 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南