[Custom Functions] Cannot find module "src/graphql/<my-module.gql>"

Hello everybody :wave:

I am working with a simple webhook called _testFn, and defined as below:

// 8base.yml

functions:
  _testFn:
    type: webhook
    handler:
      code: src/webhooks/_testFn/handler.js
    path: /testFn
    method: POST

In order to better structure my project, I created a src/graphql folder.

From the _testFn/handler.js file, I am calling the src/graphql/mutations/<name-of-my-mutation>.gql module as below :point_down:

However, when invoking locally the function using 8base invoke-local _testFn -m request, I get returned the following error message:

thrown error Cannot find module ‘src/graphql/mutations/updateTransaction.gql’

This is quite annoying because grouping all of my mutation in a single place will make me save so much time down the line.

Could someone help me figure out a way to access this src/graphql folder from the handler.js please ?

Regards,

Andréas

@andreasblondeau Hi, Andreas. At this moment you can’t use absolute imports in the custom functions code, you can use relative imports.

1 Like

@vladimir.osipov Thanks for your answer!

Using relative import, I get return the following error:

thrown error Cannot find module '../../graphql/queries/document.gql'

As you can notice, the relative path is correct.

What am I missing ?

Andréas

You’ll need to add a graphql loader to your configuration. Checkout: https://www.apollographql.com/docs/react/integrations/webpack/

Otherwise, change you gql files to js files and export the string. for example:

import gql from "graphql-tag"

export default gql`
  query { user { email } }
`