[dataset page][m]: setup dataset page to work with Apollo client connected to CKAN API.

This commit is contained in:
anuveyatsu 2020-06-23 14:07:49 +06:00
parent 1240eb8170
commit 2589ecaeeb
6 changed files with 64 additions and 18 deletions

View File

@ -4,10 +4,12 @@ import { useQuery } from '@apollo/react-hooks';
import gql from 'graphql-tag';
export const GET_DATAPACKAGE_QUERY = gql`
query dataset($id: String!) {
dataset(id: $id) {
query dataset($id: String) {
dataset(id: $id) @rest(type: "Response", path: "package_show?{args}") {
result {
name
title
size
metadata_created
metadata_modified
resources {

View File

@ -5,8 +5,8 @@ import { useQuery } from '@apollo/react-hooks';
import gql from 'graphql-tag';
export const GET_ORG_QUERY = gql`
query dataset($id: String!) {
dataset(id: $id) {
query dataset($id: String) {
dataset(id: $id) @rest(type: "Response", path: "package_show?{args}") {
result {
organization {
name

View File

@ -4,9 +4,9 @@ import { NetworkStatus } from 'apollo-client';
import { useQuery } from '@apollo/react-hooks';
import gql from 'graphql-tag';
export const DEFAULT_DATASET_QUERY = gql`
query dataset($id: String!) {
dataset(id: $id) {
export const GET_DATAPACKAGE_QUERY = gql`
query dataset($id: String) {
dataset(id: $id) @rest(type: "Response", path: "package_show?{args}") {
result {
name
resources {
@ -23,7 +23,7 @@ export const DEFAULT_DATASET_QUERY = gql`
export default function Resources({ variables }) {
const { loading, error, data, fetchMore, networkStatus } = useQuery(
DEFAULT_DATASET_QUERY,
GET_DATAPACKAGE_QUERY,
{
variables,
// Setting this value to true will make the component rerender when

View File

@ -28,6 +28,25 @@ const restLink = new RestLink({
}
return data;
},
Response: (
data: any,
outerType: string,
patchDeeper: RestLink.FunctionalTypePatcher
): any => {
if (data.result != null) {
data.result.__typename = 'Package';
if (data.result.organization != null) {
data.result.organization.__typename = 'Organization';
}
if (data.result.resources != null) {
data.result.resources = data.result.resources.map((item) => {
return { __typename: 'Resource', ...item };
});
}
}
return data;
},
},
});

View File

@ -28,6 +28,7 @@ const gdp = {
},
metadata_created: '2019-03-07T11:56:19.696257',
metadata_modified: '2019-03-07T12:03:58.817280',
size: '',
};
const population = {

View File

@ -6,16 +6,40 @@ import Head from 'next/head';
import Nav from '../../../components/home/Nav';
import About from '../../../components/dataset/About';
import Org from '../../../components/dataset/Org';
import Resources, {
DEFAULT_DATASET_QUERY,
} from '../../../components/dataset/Resources';
import Resources from '../../../components/dataset/Resources';
import gql from 'graphql-tag';
const QUERY = gql`
query dataset($id: String) {
dataset(id: $id) @rest(type: "Response", path: "package_show?{args}") {
result {
name
title
size
metadata_created
metadata_modified
resources {
name
title
format
created
last_modified
}
organization {
name
title
image_url
}
}
}
}
`;
function Dataset({ variables }) {
const {
data: {
dataset: { result },
},
} = useQuery(DEFAULT_DATASET_QUERY, { variables });
const { data, loading } = useQuery(QUERY, { variables });
if (loading) return <div>Loading</div>;
const { result } = data.dataset;
return (
<>
@ -42,8 +66,8 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
id: context.query.dataset,
};
const apolloResponse = await apolloClient.query({
query: DEFAULT_DATASET_QUERY,
await apolloClient.query({
query: QUERY,
variables,
});