0

I am using this schema to file upload:

mutation{
     uploadImg (file: Upload!): File @resolver(class: "\\Test\\Cgraphql\\Model\\Resolver\\UpImg") @doc(description:"Upload img")
}

But getting error:

Type \"Upload\" not found in document.\n\nException #0 (GraphQL\Error\Error): Type \"Upload\" not found in document.\n#1 GraphQL\Utils\ASTDefinitionBuilder->internalBuildType('Upload',

Please let me know how can we upload image in graphql.

7
  • just pass the String instead of upload and do your upload script in you resolver.
    – Mujahidh
    Commented Sep 27, 2019 at 10:17
  • but then it gives error Request content type must be application/json
    – Stack user
    Commented Sep 27, 2019 at 10:31
  • how to resolve it. have you done it before?
    – Stack user
    Commented Sep 27, 2019 at 10:31
  • explain your scope little bit more please, whether can help you in this?
    – Mujahidh
    Commented Sep 27, 2019 at 10:34
  • I want to use image upload in magento 2 graphql. can you please provide its correct schema example of mutation file upload
    – Stack user
    Commented Sep 27, 2019 at 10:43

1 Answer 1

0

You see this error because you should describe new input type which called "Upload". Your schema says: There is mutation called "uploadImg". It has one required parameter called "file". Input type of data for "file" should be "Upload" (not "String", not "Int", but "Upload"). And this mutation returns data with type "File". So, Magento can't find any declaration for input "Upload". For example, see "createCustomer" mutation and input "CustomerInput"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.