DEV Community


Posted on

The variables input contains a field name 'file' that is not defined for input object type 'CreateProductInput'

please help me to resolve this error


type Market @model @searchable @auth(rules: [{ allow : owner}, { allow: private, operations: [read]}]){
  id: ID!
  products: [Product] @hasMany
  name: String!
  tags: [String]
  owner: String!
  createAt: String

type Product @model @auth(rules: [{ allow : owner}, { allow: private, operations: [read]}]){
  id: ID!
  description: String!
  market: Market @hasOne
  file: S3Object!
  price: Float!
  shipped: Boolean!
  owner: String
  createAt: String

type S3Object @model @auth(rules: [{ allow : owner}, {allow: private, operations: [read]}]){
  bucket: String!
  region: String!
  key: String!

type User @auth(rules: [{ allow : owner}, { allow: private, operations: [read]}])
  queries: { get: "getUser" },
  mutations : { create:"regesterUser", update : "updateUser" },
  subscriptions : null
  id: ID!
  orders:[Order] @hasMany
  username: String!
  email: String!
  registered: Boolean

type Order @model(
  queries: null,
  mutations: { create: "createOrder" },
  subscriptions: null
@auth(rules: [{ allow : owner}, { allow: private, operations: [read]}])
  id: ID!
  product: Product @hasOne
  user: User @belongsTo
  ShippingAddress: ShippingAddress 

type ShippingAddress @model @auth(rules: [{ allow : owner}, {allow: private, operations: [read]}]){
  city: String!
  country: String!
  address_line1: String!
  address_state: String!
  address_zip: String!
Enter fullscreen mode Exit fullscreen mode

Note: graphql transimission version is 2

CreateProduct :

handleAddProduct = async() => {
       this.setState({ isUploading: true });
       const visibility = "public";
       const {identityId} = await Auth.currentCredentials()
       const filename = `/${visibility}/${identityId}/${}-${}`
       const uploadedFile = await Storage.put(filename, this.state.image.file, {
         contentType: this.state.image.type,
         progressCallback: progress => {
          console.log(`Uploaded: ${progress.loaded}/${}`);
          const percentUploaded = Math.round((progress.loaded/ * 100)
          this.setState({ percentUploaded });
       const file = {
         key: uploadedFile.key,
         bucket: aws_exports.aws_user_files_s3_bucket,
         region: aws_exports.aws_project_region
       const input = {
         productMarketId: this.props.marketId,
         description: this.state.description,
         shipped: this.state.shipped,
         price: convertCentsToDollar(this.state.price),
       const result = API.graphql(graphqlOperation(createProduct, { input }))
       console.log('Created Product', result);
         title: "success",
         message: "Product Successfully created!",
         type: "success" 
       this.setState({ ...initialState });

      console.error('Error adding product', err);
Enter fullscreen mode Exit fullscreen mode

Please check the code and help me to resolve the error

Thank you

Top comments (0)