I want to render on the page, simple data from manual API, but it seems that I cannot get access to the nested query.
This is what I have:
import React from 'react';
import {
gql,
graphql,
} from 'react-apollo';
//access to queries and map function
const ChannelsList = ({ data: {loading, error, items }}) => {
if (loading) {
return <p>Loading ...</p>;
}
if (error) {
return <p>{error.message}</p>;
}
return (
<div className="channelsList">
{ items.map( itm => <div key={itm.id} className="channel">{itm.sku}</div> ) }
</div>
);
};
const channelsListQuery = gql`
query ChannelsListQuery {
allLinks {
items {
id
sku
}
}
}
`;
export default graphql(channelsListQuery)(ChannelsList);
Don't mind this "channel" names, this is from example that I used for my own api. The problem is, all the queries that contain "id, names, sku" etc is in "items" type and it looks like for me it cannot get access to it. The query in graphqli server is working perfectly. So, the question is- how to get access to nested queries, so that I can use map and render it on page?
Schema structure:
const typeDefs = `
type Link {
items: [itemapi]
}
type itemapi {
id: ID!
sku: String!
name: String!
}
type Query {
allLinks: Link!
}
`;
@Solution by @OzySky
const ChannelsList = ({ data: {loading, error, allLinks }}) => {
if (loading) {
return <p>Loading ...</p>;
}
if (error) {
return <p>{error.message}</p>;
}
return (
<div className="channelsList">
{ allLinks.items.map( aLitm => <div key={aLitm.id} className="channel">{aLitm.sku}</div> ) }
</div>
);
};