剧场模式
首页前后端分离GraphQLGraphQL + React + React Router + Apollo 实战教程

GraphQL + React + React Router + Apollo 实战教程 #6 建立 apollo client - 安装 vscode 插件

海外散仙厉飞雨 · 真仙发布于
0

https://code.visualstudio.com/

https://www.apollographql.com/docs/react/essentials/get-started/

https://code.visualstudio.com/docs/setup/mac

npm install apollo-boost react-apollo graphql

client/src/components/Launches.js

import React, { Component } from 'react'
import gql from 'graphql-tag'
import { Query } from 'react-apollo'

const LAUNCHES_QUERY = gql`
  query LaunchesQuery {
    launches {
      flight_number
      mission_name
      launch_date_local
      launch_success
    }
  }
`

export class Launches extends Component {
  render() {
    return (
      <div>

      </div>
    )
  }
}

export default Launches

client/src/App.js

import React from 'react';
import './App.css';
import logo from './logo.png';

import ApolloClient from "apollo-boost";
import { ApolloProvider } from "react-apollo";

const client = new ApolloClient({
  uri: "http://localhost:4000/graphql"
});

function App() {
  return (
    <ApolloProvider client={client}>
      <div className="App">
        <img
          src={logo}
          alt="Spacex"
          style={{ width: 300, display: "block", margin: "auto" }}
        />
      </div>
    </ApolloProvider>
  );
}

export default App;
0 条回复
暂无回复~~

© 汕尾市求知科技有限公司 | 粤ICP备19038915号 | 在线学员:103

Top