Ad
{ Apollo-client, React, Grapgql } What Is Good Way Handle Multiple Loadings?
i am using react and apollo-client with graphql on Node.js
i have component which call three Query
so i have three loading like this
function MyComponent({
IsLoggedIn: { auth: { isLoggedIn } = {}, loading } = {},
GetUserInfo: { GetMyProfile: { user } = {}, loading: loading2 } = {},
lastSelectedHouse: { auth: { lastSelectedHouse } = {}, loading: loading3 } = {},
}) (
{ (!loading && !loading2 && !loading3) ? <MyComponent {...props} > : "loading" }
)
export default compose(
graphql(SELECTED_HOUSE, { name: 'lastSelectedHouse' }),
graphql(IS_LOGGED_IN, { name: 'IsLoggedIn' }),
graphql(GET_USER_INFO, {name: 'GetUserInfo'})
)(JDmiddleServer);
i don't wan't handle three loading how can i combine theme?
here is my Queries
export const IS_LOGGED_IN = gql`
{
auth {
isLoggedIn @client
}
}
`;
export const SELECTED_HOUSE = gql`
{
auth {
lastSelectedHouse @client {
label
value
}
}
}
`;
export const GET_USER_INFO = gql`
query {
GetMyProfile {
user {
_id
name
phoneNumber
password
email
isPhoneVerified
checkPrivacyPolicy
}
}
`;
Yes. two Query is for @client and one is for @server is it possible merge these Queries?
Ad
Answer
Yes, it's possible to combine the queries even though one is for the server and two for the client.
Something like this should work:
export const GET_USER_INFO = gql`
{
auth {
isLoggedIn @client
lastSelectedHouse @client {
label
value
}
}
}
query {
GetMyProfile {
user {
_id
name
phoneNumber
password
email
isPhoneVerified
checkPrivacyPolicy
}
}
`;
Depending on your schema and resolvers you should be able to design something like below which would be better.
Check the docs for combining queries: https://www.apollographql.com/docs/link/links/state.html#combine
export const GET_USER_INFO = gql`
query {
GetMyProfile {
user {
isLoggedIn @client
lastSelectedHouse @client {
label
value
}
_id
name
phoneNumber
password
email
isPhoneVerified
checkPrivacyPolicy
}
}
`;
Ad
source: stackoverflow.com
Related Questions
- → Import statement and Babel
- → should I choose reactjs+f7 or f7+vue.js?
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → .tsx webpack compile fails: Unexpected token <
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → React Native with visual studio 2015 IDE
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
- → How do I determine if a new ReactJS session and/or Browser session has started?
- → Alt @decorators in React-Native
- → How to dynamically add class to parent div of focused input field?
Ad