Practice1
GitbookGraphql2021-01-11
๐ useHooks
import React, { useState, useRef, useEffect, useContext } from "react";
import { useQuery } from "graphql";
Promise.resolve().then(() => {});
useEffect(() => func({ lazy }), [
queryResult.loading,
queryResult.error,
queryResult.data,
queryResult.networkStatus,
]);
function useDeepMemo(memoFunc, key) {
const ref = useRef();
if (!ref.current) ref.curent = { key, value: memoFunc() };
return ref.current.value;
}
const context = useContext(getApolloContext());
const [result, setResult] = useState({ called: false, loading: false });
// ({data, ...options}) = useQuery();
function Query() {
const { children, query, ...options } = props;
const result = useQuery(query, options);
return children && result ? children(result) : null;
}
๐ Material-UI Data-grid
Not fully available.
function Datagrid({ data: { Posts: rows } }) {
const columns = [
{ field: "id", hide: true },
{ field: "title", headerName: "ๆ ้ข", width: 150 },
{ field: "author", headerName: "ไฝ่
", width: 150 },
{ field: "createDate", headerName: "ๆฅๆ", width: 150 },
{ field: "description", headerName: "ๅ
ๅฎน", width: 450 },
];
return (
<div style={{ height: 500, width: "100%" }}>
<DataGrid rows={rows} columns={columns} />
</div>
);
}
๐ Understanding Caching in Apollo Client 3
- Cache Normalization: AC3 - normalized data store, unique identifier (
email
) - Fetch Policies
- Type Policies
- Field Policies
- Pagination
Apollo GraphQL cache policies:
- cache-first (Default)
- cache-and-network
- network-only
- no-cache
There are 2 types of cache:
- Client Cache
- Server Cache
๐ Jason Lengsorf: Massive Scale as Glue in IBMโs microservice architecture
Starter Kit:
- Strong starting point for new data sources
- Step-by-step tutorial for building a new data source
- Test coverage
- Pre-configured for
Travis CI
and Code Climate
Notice:
- centralize data, but decentralize control
- each data source is an independent github repo
gramps
middleware ->/graphql
GraphQL Apollo Microservice Pattern