Does follow
full code repo https://github.com/lens-protocol/lens-api-examples
This query returns to you if the Ethereum address follows a profile. It allows you to do a bulk request.
We highly advise using Is followed by me and Is following as it solves most of the cases when you want to use this.
API Design
query DoesFollow {
doesFollow(request: {
followInfos: [
{
followerAddress: "0xD020E01C0c90Ab005A01482d34B808874345FD82",
profileId: "0x01"
},
{
followerAddress: "0x248ba21F6ff51cf0CD4765C3Bc9fAD2030a591d5",
profileId: "0x01"
}
]
}) {
followerAddress
profileId
follows
}
}
{
"data": {
"doesFollow": [
{
"followerAddress": "0xD020E01C0c90Ab005A01482d34B808874345FD82",
"profileId": "0x01",
"follows": true
},
{
"followerAddress": "0x248ba21F6ff51cf0CD4765C3Bc9fAD2030a591d5",
"profileId": "0x01",
"follows": false
}
]
}
}
type Query {
doesFollow(request: DoesFollowRequest!): [DoesFollowResponse!]!
}
input DoesFollowRequest {
# The follower infos
followInfos: [DoesFollow!]!
}
input DoesFollow {
# The follower address remember wallets follow profiles
followerAddress: EthereumAddress!
# The profile id
profileId: ProfileId!
}
# ProfileId custom scalar type
scalar ProfileId
# Ethereum address custom scalar type
scalar EthereumAddress
# hint: it returns an array of this type
# The does follow response
type DoesFollowResponse {
# The follower address remember wallets follow profiles
followerAddress: EthereumAddress!
# The profile id
profileId: ProfileId!
# If the user does follow
follows: Boolean!
}
# ProfileId custom scalar type
scalar ProfileId
# Ethereum address custom scalar type
scalar EthereumAddress
Full code example
import { apolloClient } from './apollo-client';
// this is showing you how you use it with react for example
// if your using node or something else you can import using
// @apollo/client/core!
import { gql } from '@apollo/client'
const DOES_FOLLOW = `
query($request: DoesFollowRequest!) {
doesFollow(request: $request) {
followerAddress
profileId
follows
}
}
`
export const doesFollow = (followInfos) => {
return apolloClient.query({
query: gql(DOES_FOLLOW),
variables: {
request: {
followInfos,
},
},
})
}
// this is showing you how you use it with react for example
// if your using node or something else you can import using
// @apollo/client/core!
import { ApolloClient, InMemoryCache, HttpLink, ApolloLink } from '@apollo/client'
const httpLink = new HttpLink({ uri: 'https://api-mumbai.lens.dev/' });
// example how you can pass in the x-access-token into requests using `ApolloLink`
const authLink = new ApolloLink((operation, forward) => {
// Retrieve the authorization token from local storage.
// if your using node etc you have to handle your auth different
const token = localStorage.getItem('auth_token');
// Use the setContext method to set the HTTP headers.
operation.setContext({
headers: {
'x-access-token': token ? `Bearer ${token}` : ''
}
});
// Call the next link in the middleware chain.
return forward(operation);
});
export const apolloClient = new ApolloClient({
link: authLink.concat(httpLink),
cache: new InMemoryCache(),
})
Updated 3 days ago
Did this page help you?