Skip to content
This repository was archived by the owner on Jun 9, 2023. It is now read-only.

Initial setup apollo on client #393

Merged
merged 16 commits into from
Aug 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Setup simple GQL query
  • Loading branch information
Zeko369 committed Aug 2, 2020
commit ce9c7538bb8df613940e21c1bf537c2e2840a9ef
4 changes: 2 additions & 2 deletions client/codegen.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module.exports = {
schema: [{ 'http://localhost:4000/graphql': {} }],
documents: ['./src/**/*.tsx'],
documents: ['./src/**/graphql/*.ts'],
overwrite: true,
generates: {
'./generated/index.tsx': {
'./src/generated/index.tsx': {
plugins: [
'typescript',
'typescript-operations',
Expand Down
3 changes: 1 addition & 2 deletions client/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import SomeComponent from './SomeComponent';
import AddSponsor from './AddSponsor';
import ProgressCardContent from './ProgressCardContent';

export { SomeComponent, AddSponsor, ProgressCardContent };
export { AddSponsor, ProgressCardContent };
5 changes: 4 additions & 1 deletion client/src/generated/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,17 @@ export type UpdateVenueInputs = {
export type ChaptersQueryVariables = Exact<{ [key: string]: never }>;

export type ChaptersQuery = { __typename?: 'Query' } & {
chapters: Array<{ __typename?: 'Chapter' } & Pick<Chapter, 'id' | 'name'>>;
chapters: Array<
{ __typename?: 'Chapter' } & Pick<Chapter, 'id' | 'name' | 'description'>
>;
};

export const ChaptersDocument = gql`
query chapters {
chapters {
id
name
description
}
}
`;
Expand Down
53 changes: 0 additions & 53 deletions client/src/modules/home.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { gql } from '@apollo/client';

export const MainQuery = gql`
export const CHAPTERS_QUERY = gql`
query chapters {
chapters {
id
name
description
}
}
`;
48 changes: 48 additions & 0 deletions client/src/modules/home/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from 'react';
import Link from 'next/link';
import { Card, Typography, Grid } from '@material-ui/core';

import { ProgressCardContent } from '../../components';
import { useChaptersQuery } from '../../generated';

const Home: React.FC = () => {
const { loading, error, data } = useChaptersQuery();

return (
<>
<Grid container spacing={2}>
<Grid item xs={10}>
{!error && (
<Card>
<ProgressCardContent loading={loading}>
{data?.chapters.map(chapter => (
<>
<Typography gutterBottom variant="h5" component="h2">
{chapter.name}
</Typography>
<Typography
variant="body2"
color="textSecondary"
component="p"
>
{chapter.description}
</Typography>
</>
))}
</ProgressCardContent>
</Card>
)}
</Grid>
</Grid>
<Link href="/add-sponsor">
<a>Add sponsor</a>
</Link>
<br />
<Link href="/dashboard">
<a>Admin dashboard</a>
</Link>
</>
);
};

export default Home;
24 changes: 16 additions & 8 deletions client/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { applyMiddleware, compose, createStore } from 'redux';
import thunk from 'redux-thunk';
import { ThemeProvider as MaterialUIThemeProvider } from '@material-ui/core/styles';
import CssBaseline from '@material-ui/core/CssBaseline';
import { ApolloClient, InMemoryCache, ApolloProvider } from '@apollo/client';

import theme from '../styles/theme';
import { rootReducer } from '../store/reducers';
Expand All @@ -21,6 +22,11 @@ const store = createStore(
composeEnhancers(applyMiddleware(thunk)),
);

const client = new ApolloClient({
uri: 'http://localhost:4000/graphql',
cache: new InMemoryCache(),
});

export default class MyApp extends App {
render() {
const { Component, pageProps } = this.props;
Expand All @@ -35,14 +41,16 @@ export default class MyApp extends App {
/>
<meta name="theme-color" content={theme.palette.primary.main} />
</Head>
<Provider store={store}>
<MaterialUIThemeProvider theme={theme}>
<CssBaseline />
<PageLayout>
<Component {...pageProps} />
</PageLayout>
</MaterialUIThemeProvider>
</Provider>
<ApolloProvider client={client}>
<Provider store={store}>
<MaterialUIThemeProvider theme={theme}>
<CssBaseline />
<PageLayout>
<Component {...pageProps} />
</PageLayout>
</MaterialUIThemeProvider>
</Provider>
</ApolloProvider>
</>
);
}
Expand Down