import { ApolloClient, InMemoryCache, HttpLink, gql } from '@apollo/client';
const MEMBER_DETAILS = gql`
query Member {
member {
name
role
session @client {
isLoggedIn
connectionCount
errors
}
}
}
`;
const client = new ApolloClient({
link: new HttpLink({ uri: 'http://localhost:4000/graphql' }),
cache: new InMemoryCache(),
resolvers: {
Member: {
session() {
return {
__typename: 'Session',
isLoggedIn: someInternalLoginVerificationFunction(),
connectionCount: calculateOpenConnections(),
errors: sessionError(),
};
}
}
},
});
import { ApolloClient, InMemoryCache, HttpLink, gql } from '@apollo/client';
const MEMBER_DETAILS = gql`
query Member {
member {
name
role
isLoggedIn @client
}
}
`;
const client = new ApolloClient({
link: new HttpLink({ uri: 'http://localhost:4000/graphql' }),
cache: new InMemoryCache(),
resolvers: {
Member: {
isLoggedIn() {
return someInternalLoginVerificationFunction();
}
}
},
});
// ... run the query using client.query, the <Query /> component, etc.
import { ApolloClient, InMemoryCache, HttpLink, gql } from '@apollo/client';
const query = gql`
query CurrentAuthorPostCount($authorId: Int!) {
currentAuthorId @client @export(as: "authorId")
postCount(authorId: $authorId)
}
`;
const cache = new InMemoryCache();
const client = new ApolloClient({
link: new HttpLink({ uri: 'http://localhost:4000/graphql' }),
cache,
resolvers: {},
});
cache.writeQuery({
query: gql`query GetCurrentAuthorId { currentAuthorId }`,
data: {
currentAuthorId: 12345,
},
});
// ... run the query using client.query, the <Query /> component, etc.
import { ApolloClient, InMemoryCache, HttpLink, gql } from '@apollo/client';
const query = gql`
query CurrentAuthorPostCount($authorId: Int!) {
currentAuthor @client {
name
authorId @export(as: "authorId")
}
postCount(authorId: $authorId)
}
`;
const cache = new InMemoryCache();
const client = new ApolloClient({
link: new HttpLink({ uri: 'http://localhost:4000/graphql' }),
cache,
resolvers: {},
});
cache.writeQuery({
query: gql`
query GetCurrentAuthor {
currentAuthor {
name
authorId
}
}
`,
data: {
currentAuthor: {
__typename: 'Author',
name: 'John Smith',
authorId: 12345,
},
},
});
// ... run the query using client.query, the <Query /> component, etc.
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
const typeDefs = gql`
extend type Query {
isLoggedIn: Boolean!
cartItems: [Launch]!
}
extend type Launch {
isInCart: Boolean!
}
extend type Mutation {
addOrRemoveFromCart(id: ID!): [Launch]
}
`;
const client = new ApolloClient({
cache: new InMemoryCache(),
uri: 'http://localhost:4000/graphql',
typeDefs,
});