How to use the mst-gql.createHttpClient function in mst-gql

To help you get started, we’ve selected a few mst-gql examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mobxjs / mst-gql / examples / 5-todos / src / index.js View on Github external
import * as React from "react"
import { createHttpClient } from "mst-gql"

import { render } from "react-dom"
import { TodoListView } from "./TodoListView"
import { RootStore } from "./models"

const ENDPOINT = `https://api.graphcms.com/simple/v1/cjfmozsww0sn70146fdqyuhst`

const store = RootStore.create(undefined, {
  gqlHttpClient: createHttpClient(ENDPOINT)
})

render(, document.getElementById("root"))
github mobxjs / mst-gql / examples / 5-nextjs / utils / initModels.ts View on Github external
export function initializeStore(
  isServer: boolean,
  snapshot = null
): ModelCreationType {
  if (isServer) {
    store = RootStore.create(undefined, {
      gqlHttpClient: createHttpClient("http://localhost:3000/api/graphql"),
      ssr: true
    })
  }
  if (store === null) {
    store = RootStore.create(undefined, {
      gqlHttpClient: createHttpClient("http://localhost:3000/api/graphql")
    })
  }
  if (snapshot) {
    applySnapshot(store, snapshot)
  }
  return store
}
github mobxjs / mst-gql / examples / 5-nextjs / pages / _app.tsx View on Github external
export function getStore(snapshot = null): ModelCreationType {
  if (isServer || !store) {
    store = RootStore.create(undefined, {
      gqlHttpClient: createHttpClient("http://localhost:3000/api/graphql"),
      ssr: true
    })
  }
  if (snapshot) {
    applySnapshot(store, snapshot)
  }
  return store
}
github mobxjs / mst-gql / examples / 4-apollo-tutorial / client / src / index.js View on Github external
import React from "react"
import ReactDOM from "react-dom"

import { Observer } from "mobx-react-lite"

import Pages from "./pages"
import Login from "./pages/login"
import injectStyles from "./styles"

import { createHttpClient } from "mst-gql"

import { RootStore } from "./models"
import { StoreContext } from "./models/reactUtils"

const gqlHttpClient = createHttpClient("http://localhost:4000/graphql", {
  headers: {
    authorization: localStorage.getItem("token"),
    "client-name": "Space Explorer [web]",
    "client-version": "1.0.0"
  }
})

const rootStore = RootStore.create(
  {
    loginStatus: localStorage.getItem("token") ? "loggedIn" : "loggedOut",
    cartItems: []
  },
  {
    gqlHttpClient
  }
)
github mobxjs / mst-gql / examples / 1-getting-started / src / app / index.tsx View on Github external
import React from "react"
import * as ReactDOM from "react-dom"
import { createHttpClient } from "mst-gql"

import "./index.css"

import { RootStore } from "./models/RootStore"
import { StoreContext } from "./models/reactUtils"
import { Home } from "./Home"

const rootStore = RootStore.create(undefined, {
  gqlHttpClient: createHttpClient("http://localhost:3001/graphql")
})

export const App: React.FC = () => (
  
    <main>
      <h1>Todos</h1>
      
    </main>
  
)

ReactDOM.render(, document.getElementById("root"))
github mobxjs / mst-gql / examples / 3-twitter-clone / src / app / index.tsx View on Github external
import React from "react"
import * as ReactDOM from "react-dom"
import { createHttpClient } from "mst-gql"
import { SubscriptionClient } from "subscriptions-transport-ws"

import "./index.css"

import { RootStore } from "./models/RootStore"
import { StoreContext } from "./models/reactUtils"

import { Home } from "./components/Home"
import { Profile } from "./components/Profile"

const gqlHttpClient = createHttpClient("http://localhost:4000/graphql")

const gqlWsClient = new SubscriptionClient("ws://localhost:4000/graphql", {
  reconnect: true
})

const rootStore = RootStore.create(undefined, {
  gqlHttpClient,
  gqlWsClient
})

export const App = () =&gt; (
  
    <main>
      
      
    </main>