@apollo/client/core#gql TypeScript Examples
The following examples show how to use
@apollo/client/core#gql.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: discussions-trigger.ts From dt-mergebot with MIT License | 6 votes |
async function getLabelByName(name: string) {
const info = await client.query({
query: gql`
query GetLabel($name: String!) {
repository(name: "DefinitelyTyped", owner: "DefinitelyTyped") {
id
name
labels(query: $name, first: 1) {
nodes {
id
name
}
}
}
}`,
variables: { name },
fetchPolicy: "no-cache",
});
const label: { id: string, name: string } | undefined = info.data.repository.labels.nodes[0];
return { repoID: info.data.repository.id, label };
}
Example #2
Source File: Security.ts From jmix-frontend with Apache License 2.0 | 6 votes |
PERMISSIONS_QUERY = gql`query {
permissions {
entities {
target
value
},
entityAttributes {
target
value
}
specifics {
target
value
}
${process.env.REACT_APP_ENABLE_UI_PERMISSIONS === "true"
? `
menus {
target
value
}
screens {
target
value
}`
: ""
}
}
}`
Example #3
Source File: price-scan.ts From runebot with MIT License | 6 votes |
async function getVaultTokens() {
const ids = [];
const url = `https://api.thegraph.com/subgraphs/name/nftx-project/nftx-v2`;
const query = `
query {
vault(id:"0x87931e7ad81914e7898d07c68f145fc0a553d8fb") {
holdings (first: 1000) {
tokenId
}
}
}
`
const client = new ApolloClient({
uri: url,
cache: new InMemoryCache()
});
try {
const response = await client.query({
query: gql(query)
})
for (const wiz of response.data.vault.holdings) {
ids.push(wiz.tokenId);
}
} catch(error) {
console.log(error);
}
checkVaultIds(ids);
}
Example #4
Source File: apps-commit.ts From amplication with Apache License 2.0 | 6 votes |
COMMIT_CHANGES = gql`
mutation commit($message: String!, $appId: String!) {
commit(data: { message: $message, app: { connect: { id: $appId } } }) {
id
createdAt
userId
message
builds {
id
}
}
}
`
Example #5
Source File: pool.test.ts From balancer-subgraph-v2 with MIT License | 6 votes |
testCases = [
{
id: 'getPools',
query: gql`
query {
pools {
tokens {
id
}
id
}
}
`,
},
]
Example #6
Source File: account.service.ts From etherspot-sdk with MIT License | 6 votes |
async getConnectedAccounts(page: number): Promise<Accounts> {
const { apiService } = this.services;
const { result } = await apiService.query<{
result: Accounts;
}>(
gql`
query($chainId: Int, $page: Int) {
result: accounts(chainId: $chainId, page: $page) {
items {
address
type
state
store
createdAt
updatedAt
}
currentPage
nextPage
}
}
`,
{
variables: {
page: page || 1,
},
models: {
result: Accounts,
},
},
);
return result;
}
Example #7
Source File: admin.profile.fragment.ts From ui with GNU Affero General Public License v3.0 | 6 votes |
ADMIN_PROFILE_FRAGMENT = gql`
fragment AdminProfile on Profile {
id
email
username
language
firstName
lastName
roles
created
lastModified
}
`
Example #8
Source File: InvalidationPolicyCache.ts From apollo-cache-policies with Apache License 2.0 | 5 votes |
protected updateCollectionField(typename: string, dataId: string) {
// Since colletion support is still experimental, only record entities in collections if enabled
if (!this.enableCollections) {
return;
}
const collectionEntityId = collectionEntityIdForType(typename);
const collectionFieldExists = !!this.readField<Record<string, any[]>>('id', makeReference(collectionEntityId));
// If the collection field for the type does not exist in the cache, then initialize it as
// an empty array.
if (!collectionFieldExists) {
this.writeFragment({
id: collectionEntityId,
fragment: gql`
fragment InitializeCollectionEntity on CacheExtensionsCollectionEntity {
data
id
}
`,
data: {
__typename: cacheExtensionsCollectionTypename,
id: typename,
data: [],
},
});
}
// If the entity does not already exist in the cache, add it to the collection field policy for its type
if (!this.entityTypeMap.readEntityById(dataId)) {
this.modify({
broadcast: false,
id: collectionEntityId,
fields: {
data: (existing, { canRead }) => {
return [
...existing.filter((ref: Reference) => canRead(ref)),
makeReference(dataId),
];
}
}
});
}
}
Example #9
Source File: nftx.service.ts From runebot with MIT License | 5 votes |
/**
* Get OS sales for specific collection
*/
public async getSales(collection: CollectionConfig): Promise<Sale[]> {
const timestamp =
Math.floor(Date.now() / 1000) -
Number(this.configService.bot.salesLookbackSeconds);
const NFTX_GET_REDEEM = gql`
{
redeems(
first: 100,
where: { date_gt: "${timestamp}", vault: "${collection.nftxVaultContract}" },
orderBy: date,
orderDirection: desc
) {
id
zapAction {
ethAmount
id
}
vault {
id
vaultId
token {
symbol
}
asset {
id
}
}
user {
id
}
date
nftIds
specificIds
randomCount
targetCount
feeReceipt {
transfers {
amount
}
date
}
}
}`;
let sales: Array<Sale> = [];
try {
this._logger.log(`Checking for sales${collection.openSeaSlug}/NFTx`);
const response = await this._nftxClient.query({
query: NFTX_GET_REDEEM,
});
if (response.error) {
this._logger.debug(response.error);
}
if (response.data.redeems.length) {
sales = await this.createSales(response.data.redeems, collection);
this._logger.log(
`Found ${sales.length} sales ${collection.openSeaSlug}/NFTx`,
);
} else {
this._logger.log(`No sales ${collection.openSeaSlug}/NFTx`);
}
} catch (error) {
this._logger.error(error);
} finally {
return sales.reverse();
}
}
Example #10
Source File: ra-auth-http.ts From amplication with Apache License 2.0 | 5 votes |
LOGIN = gql`
mutation login($username: String!, $password: String!) {
login(credentials: { username: $username, password: $password }) {
username
roles
}
}
`
Example #11
Source File: account.service.ts From etherspot-sdk with MIT License | 5 votes |
async syncAccount(): Promise<Account> {
const { apiService } = this.services;
switch (this.account.type) {
case AccountTypes.Key: {
const { account } = await apiService.mutate<{
account: Account;
}>(
gql`
mutation($chainId: Int) {
account: syncAccount(chainId: $chainId) {
address
type
state
store
createdAt
updatedAt
}
}
`,
{
models: {
account: Account,
},
},
);
this.account$.next(account);
break;
}
case AccountTypes.Contract: {
const {
accountMember: { account, ...accountMember },
} = await apiService.mutate<{
accountMember: AccountMember;
}>(
gql`
mutation($chainId: Int, $account: String!) {
accountMember: syncAccountMember(chainId: $chainId, account: $account) {
account {
address
type
state
store
createdAt
updatedAt
}
type
state
store
createdAt
updatedAt
}
}
`,
{
variables: {
account: this.accountAddress,
},
models: {
accountMember: AccountMember,
},
},
);
this.account$.next(account);
this.accountMember$.next(accountMember);
break;
}
}
return this.account;
}