feat: show connection upon verification
This commit is contained in:
@@ -1,6 +1,10 @@
|
|||||||
import { InMemoryCache } from '@apollo/client';
|
import { InMemoryCache } from '@apollo/client';
|
||||||
import offsetLimitPagination from './pagination';
|
import offsetLimitPagination from './pagination';
|
||||||
|
|
||||||
|
interface IRef {
|
||||||
|
__ref: string;
|
||||||
|
}
|
||||||
|
|
||||||
const cache = new InMemoryCache({
|
const cache = new InMemoryCache({
|
||||||
typePolicies: {
|
typePolicies: {
|
||||||
App: {
|
App: {
|
||||||
@@ -9,9 +13,9 @@ const cache = new InMemoryCache({
|
|||||||
Mutation: {
|
Mutation: {
|
||||||
mutationType: true,
|
mutationType: true,
|
||||||
fields: {
|
fields: {
|
||||||
createConnection: {
|
verifyConnection: {
|
||||||
merge(existing, newConnection, { readField, cache }) {
|
merge(existing, verifiedConnection, { readField, cache }) {
|
||||||
const appKey = readField('key', newConnection);
|
const appKey = readField('key', verifiedConnection);
|
||||||
const appCacheId = cache.identify({
|
const appCacheId = cache.identify({
|
||||||
__typename: 'App',
|
__typename: 'App',
|
||||||
key: appKey,
|
key: appKey,
|
||||||
@@ -21,12 +25,22 @@ const cache = new InMemoryCache({
|
|||||||
id: appCacheId,
|
id: appCacheId,
|
||||||
fields: {
|
fields: {
|
||||||
connections: (existingConnections) => {
|
connections: (existingConnections) => {
|
||||||
return [...existingConnections, newConnection];
|
const existingConnectionIndex = existingConnections.findIndex((connection: IRef) => {
|
||||||
|
return connection.__ref === verifiedConnection.__ref;
|
||||||
|
});
|
||||||
|
const connectionExists = existingConnectionIndex !== -1;
|
||||||
|
|
||||||
|
// newly created and verified connection
|
||||||
|
if (!connectionExists) {
|
||||||
|
return [verifiedConnection, ...existingConnections];
|
||||||
|
}
|
||||||
|
|
||||||
|
return existingConnections;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return newConnection;
|
return verifiedConnection;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -11,9 +11,6 @@ export const CREATE_CONNECTION = gql`
|
|||||||
formattedData {
|
formattedData {
|
||||||
screenName
|
screenName
|
||||||
}
|
}
|
||||||
app {
|
|
||||||
key
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
@@ -4,10 +4,15 @@ export const VERIFY_CONNECTION = gql`
|
|||||||
mutation VerifyConnection($input: VerifyConnectionInput) {
|
mutation VerifyConnection($input: VerifyConnectionInput) {
|
||||||
verifyConnection(input: $input) {
|
verifyConnection(input: $input) {
|
||||||
id
|
id
|
||||||
|
key
|
||||||
verified
|
verified
|
||||||
formattedData {
|
formattedData {
|
||||||
screenName
|
screenName
|
||||||
}
|
}
|
||||||
|
createdAt
|
||||||
|
app {
|
||||||
|
key
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
Reference in New Issue
Block a user