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달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠