Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apiClient().get is not a function #7

Open
pereriksson opened this issue Jan 3, 2021 · 2 comments
Open

apiClient().get is not a function #7

pereriksson opened this issue Jan 3, 2021 · 2 comments

Comments

@pereriksson
Copy link

pereriksson commented Jan 3, 2021

I have tried this example with both axios and fetch drivers. I can though only get it to work for the fetch-adapter:

// TasksCollection.js
const apiPath = '/api'
import adapter from 'mobx-rest-axios-adapter'
import { apiClient, Collection, Model } from 'mobx-rest'

apiClient(adapter, { apiPath })

class Task extends Model { }
class Tasks extends Collection {
    url ()  { return `/tasks` }
    model () { return Task }
}

export default new Tasks()

// In a Mithril component
import tasksCollection from "../../mobx/TasksCollection";
tasksCollection.fetch({ data: { all: true } });

The error I get from this driver is:

TypeError: apiClient(...).get is not a function
    at Tasks.Collection.fetch (index.js:885)
    at executeAction$$1 (mobx.module.js:660)
    at Tasks.res (mobx.module.js:651)
@masylum
Copy link
Contributor

masylum commented Jan 9, 2021

hmmm.. That's strange, we actually use the axios adapter in Factorial in production. This is how we set it up:

// src/initializers/mobxRest.js
import adapter from 'factorial-mobx-rest-axios-adapter'
import { apiClient } from 'mobx-rest'
import { apiEndpoint } from 'config/Vars'

export default () => {
  apiClient(adapter, {
    apiPath: apiEndpoint,
    commonOptions: { withCredentials: true }
  })
}

@masylum
Copy link
Contributor

masylum commented Jan 9, 2021

Perhaps the loading order is incorrect? We call this initializer before doing anything in the application to ensure the adapter is setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants