MONEI / Shopify-api-node

Node Shopify connector sponsored by MONEI
https://monei.com/shopify-payment-gateway/
MIT License
945 stars 278 forks source link

Reading files with GraphQl #519

Closed PrateekGoyal18 closed 1 year ago

PrateekGoyal18 commented 2 years ago

I am trying to read the files that I have uploaded in shopify backend with the help of this code:

const shopify = new Shopify({
  shopName: process.env.STORE_NAME,
  apiKey: process.env.API_KEY,
  password: process.env.STORE_PASSWORD,
});
const query = `{
  files {
    edges {
      node {
        alt
      }
    }
  }
}`;
shopify
  .graphql(query)
  .then((files) => console.log(files))
  .catch((err) => console.error(err));

But I am running into this error

Error: Field 'files' doesn't exist on type 'QueryRoot'
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  locations: [ { line: 2, column: 7 } ],
  path: [ 'query', 'files' ],
  extensions: { code: 'undefinedField', typeName: 'QueryRoot', fieldName: 'files' },
  response: <ref *1> PassThrough {
    _readableState: ReadableState {
      objectMode: false,
      highWaterMark: 16384,
      buffer: BufferList { head: null, tail: null, length: 0 },
      length: 0,
      pipes: [],
      flowing: false,
      ended: true,
      endEmitted: true,
      reading: false,
      constructed: true,
      sync: false,
      needReadable: false,
      emittedReadable: false,
      readableListening: true,
      resumeScheduled: false,
      errorEmitted: false,
      emitClose: true,
      autoDestroy: false,
      destroyed: false,
      errored: null,
      closed: false,
      closeEmitted: false,
      defaultEncoding: 'utf8',
      awaitDrainWriters: null,
      multiAwaitDrain: false,
      readingMore: false,
      decoder: null,
      encoding: null,
      [Symbol(kPaused)]: null
    },
    _destroy: [Function: destroy],
    _events: [Object: null prototype] {
      prefinish: [Function: prefinish],
      error: [Function],
      aborted: [Function],
      readable: [Function (anonymous)]
    },
    _eventsCount: 4,
    _maxListeners: undefined,
    _writableState: WritableState {
      objectMode: false,
      highWaterMark: 16384,
      finalCalled: true,
      needDrain: false,
      ending: true,
      ended: true,
      finished: true,
      destroyed: false,
      decodeStrings: true,
      defaultEncoding: 'utf8',
      length: 0,
      writing: false,
      corked: 0,
      sync: false,
      bufferProcessing: false,
      onwrite: [Function: bound onwrite],
      writecb: null,
      writelen: 0,
      afterWriteTickInfo: null,
      buffered: [],
      bufferedIndex: 0,
      allBuffers: true,
      allNoop: true,
      pendingcb: 0,
      constructed: true,
      prefinished: true,
      errorEmitted: false,
      emitClose: true,
      autoDestroy: false,
      errored: null,
      closed: false,
      closeEmitted: false,
      [Symbol(kOnFinished)]: []
    },
    allowHalfOpen: true,
    socket: [Getter/Setter],
    httpVersionMajor: [Getter/Setter],
    httpVersionMinor: [Getter/Setter],
    httpVersion: [Getter/Setter],
    complete: [Getter/Setter],
    rawHeaders: [Getter/Setter],
    rawTrailers: [Getter/Setter],
    aborted: [Getter/Setter],
    upgrade: [Getter/Setter],
    url: [Getter/Setter],
    method: [Getter/Setter],
    statusCode: [Getter/Setter],
    statusMessage: [Getter/Setter],
    client: [Getter/Setter],
    _consuming: [Getter/Setter],
    _dumped: [Getter/Setter],
    req: [Getter/Setter],
    timings: [Getter/Setter],
    headers: [Getter/Setter],
    setTimeout: [Getter/Setter],
    trailers: [Getter/Setter],
    requestUrl: 'https://dianakorrwholesale.myshopify.com/admin/api/graphql.json',
    redirectUrls: [],
    request: Request {
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 14,
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: true,
      requestInitialized: true,
      redirects: [],
      retryCount: 0,
      _progressCallbacks: [],
      write: [Function: onLockedWrite],
      end: [Function: onLockedWrite],
      options: [Object],
      requestUrl: 'https://dianakorrwholesale.myshopify.com/admin/api/graphql.json',
      _cannotHaveBody: false,
      _noPipe: true,
      [Symbol(kCapture)]: false,
      [Symbol(downloadedSize)]: 217,
      [Symbol(uploadedSize)]: 111,
      [Symbol(serverResponsesPiped)]: Set(0) {},
      [Symbol(stopReading)]: false,
      [Symbol(triggerRead)]: true,
      [Symbol(jobs)]: [],
      [Symbol(body)]: '{\n' +
        '      files(first:250) {\n' +
        '        edges {\n' +
        '          node {\n' +
        '            alt\n' +
        '          }\n' +
        '        }\n' +
        '      }\n' +
        '    }',
      [Symbol(bodySize)]: 111,
      [Symbol(cancelTimeouts)]: [Function: cancelTimeouts],
      [Symbol(unproxyEvents)]: [Function (anonymous)],
      [Symbol(request)]: [ClientRequest],
      [Symbol(originalResponse)]: [IncomingMessage],
      [Symbol(isFromCache)]: false,
      [Symbol(responseSize)]: 217,
      [Symbol(response)]: [Circular *1],
      [Symbol(startedReading)]: true
    },
    isFromCache: false,
    ip: '23.227.38.74',
    retryCount: 0,
    rawBody: <Buffer 7b 22 65 72 72 6f 72 73 22 3a 5b 7b 22 6d 65 73 73 61 67 65 22 3a 22 46 69 65 6c 64 20 27 66 69 6c 65 73 27 20 64 6f 65 73 6e 27 74 20 65 78 69 73 74 ... 167 more bytes>,
    body: { errors: [Array] },
    [Symbol(kCapture)]: false,
    [Symbol(kCallback)]: null
  }
}

Please if anyone can help me I will really appreciate it. Thank you!

ozzyonfire commented 1 year ago

Make sure you are using an 'apiVersion' which files exists on. I think by default this library will use an older version if none is specified.

So add apiVersion: '2022-07' (or whatever one you want) to your configuration when instantiating the API.

lpinca commented 1 year ago

I'm closing this as answered by @ozzyonfire's comment.