Each user account is associated with an authority, which is the owner of the account. To query the user details associated with an authority, we query the User account’s authority field using the _eq filter. Please note, the User account fields can be handpicked as per your applications requirements.
You can directly copy paste this code on replit and see it in action.
Fetch User Details for an Authority
constSHYFT_API_KEY="YOUR-API-KEY";asyncfunctiongetDataByGraphQl(authorityAddress) {//get user by authorityconstoperationsDoc=` query MyQuery { drift_User( limit: 10 where: {authority: {_eq: ${JSON.stringify(authorityAddress)}}} ) { delegate subAccountId pubkey authority } } `; //graphQl queryconstresult=awaitfetch(`https://programs.shyft.to/v0/graphql/accounts?api_key=${SHYFT_API_KEY}&network=mainnet-beta`,//SHYFT's GQL endpoint { method:"POST", body:JSON.stringify({ query: operationsDoc, variables: {}, operationName:"MyQuery", }), }, );returnawaitresult.json();}asyncfunctiongetUserDetailsByAuthority(authorityPubkey) {const { errors,data } =awaitgetDataByGraphQl(authorityPubkey);if (errors) {console.error(errors);console.log("Some Error Occured, please check your API key or try again"); }console.dir(data, { depth:null });}getUserDetailsByAuthority("Ctae6pxZZYKQ2tZRavw1tEVhVN5YNRJRhTBFGDbipmtw")//authority address of the user to be fetched