Using other npm packages in Autotask code

I am trying to use graphql-hooks package to call graphql endpoint and get data which will be the input to the contract method, but getting error 'Error: Cannot find module 'graphql-hooks'' while running autotask. Can we import any packages in autotask code ?

:computer: Environment

:memo:Details
Using other packages in Autotask of Defender

I am trying to use graphql-hooks package to call graphql endpoint and get data which will be the input to the contract method, but getting error 'Error: Cannot find module 'graphql-hooks'' while running autotask. Can we import any packages in autotask code ? Or Can we pass inputs to the autotask code which can be passed to contract methods while invoking.

:1234: Code to reproduce

Hey @kbhargav5! The recommended way for adding extra dependencies to the autotask is to use a bundler (like rollup or webpack) for bundling them into a single file or directory that is uploaded to the Autotask. You can check out some examples in this repo:

Now, from what I see, graphql-hooks is a library for querying graphql from React in a UI. Given that Autotasks are backend functions, and do not have a UI, have you considered a different library for querying a graphql endpoint? We include both @apollo/client and graphql-request in the autotask env, both of which could help here!

Thanks @spalladino.
I am running scheduled autotask and want to use graphql library inside autotask.
I tried using @apollo/client and graphql-request inside autotask. Both of them gave following errors respectively.

  1. Error: Cannot find module 'graphql'. ---> this is from @apollo/client
  2. Cannot find module: 'graphql/language/printer'. ---> this is from graphql-request
    Looks like both have dependency on graphql module which is not included in autotask env

Indeed, the peer dependency is missing. Stay tuned, we'll deploy a fix today.

@kbhargav5 this should be now fixed for graphql-request. Keep in mind you'll need to create a new Autotask to get the latest version of the dependencies.