My React Learning Note (6)

GraphQL

My React Learning Note (6)

https://github.com/ZhangMYihua/crwn-clothing-prisma

Apollo

Apollo basic:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { ApolloProvider } from "react-apollo";
import { createHttpLink } from "apollo-link-http";
import { InMemoryCache } from "apollo-cache-inmemory";
import { ApolloClient, gql } from "apollo-boost";
import "./index.css";
import App from "./App";

const httpLink = createHttpLink({
uri: "https://crwn-clothing.com",
});

const cache = new InMemoryCache();

const client = new ApolloClient({
link: httpLink,
cache,
});

client
.query({
query: gql`
{
getCollectionsByTitle(title: "hats") {
id
title
items {
id
name
price
imageUrl
}
}
}
`,
})
.then((res) => console.log(res));

本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!