Skip to content

Commit

Permalink
feat: fetch mods and vips over gql (#651)
Browse files Browse the repository at this point in the history
  • Loading branch information
iProdigy committed Sep 17, 2022
1 parent fbdfdd7 commit b02a699
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 0 deletions.
@@ -0,0 +1,19 @@
query fetchMods($channelLogin: String!, $first: Int = 10, $after: Cursor) {
user(login: $channelLogin) {
id
mods(first: $first, after: $after) {
edges {
cursor
grantedAt
node {
id
displayName
login
}
}
pageInfo {
hasNextPage
}
}
}
}
@@ -0,0 +1,19 @@
query fetchVips($channelLogin: String!, $first: Int = 10, $after: Cursor) {
user(login: $channelLogin) {
id
vips(first: $first, after: $after) {
edges {
cursor
grantedAt
node {
id
displayName
login
}
}
pageInfo {
hasNextPage
}
}
}
}
Expand Up @@ -250,6 +250,10 @@ public CommandFetchModComments fetchModComments(OAuth2Credential auth, String ch
return new CommandFetchModComments(getApolloClient(auth), channelId, targetId, after);
}

public CommandFetchMods fetchMods(OAuth2Credential auth, String channelLogin, String after, Integer limit) {
return new CommandFetchMods(getApolloClient(auth), channelLogin, after, limit);
}

public CommandArchivePoll archivePoll(OAuth2Credential auth, String pollId) {
return new CommandArchivePoll(getApolloClient(auth), pollId);
}
Expand Down Expand Up @@ -339,6 +343,10 @@ public CommandFetchVideoComments fetchVideoComments(OAuth2Credential auth, Strin
return new CommandFetchVideoComments(getApolloClient(auth), channelId, videoId, id, after, before, first, last);
}

public CommandFetchVips fetchVips(OAuth2Credential auth, String channelLogin, String after, Integer limit) {
return new CommandFetchVips(getApolloClient(auth), channelLogin, after, limit);
}

/**
* Follow a user
*
Expand Down
@@ -0,0 +1,49 @@
package com.github.twitch4j.graphql.command;

import com.apollographql.apollo.ApolloCall;
import com.apollographql.apollo.ApolloClient;
import com.github.twitch4j.graphql.internal.FetchModsQuery;

public class CommandFetchMods extends BaseCommand<FetchModsQuery.Data> {

/**
* The login name of the channel whose mod list is being queried
*/
private final String channelLogin;

/**
* Relay cursor for forward pagination (optional)
*/
private final String cursor;

/**
* The maximum number of nodes to return in a single call
*/
private final int limit;

/**
* Constructor
*
* @param apolloClient Apollo Client
* @param channelLogin The login name of the channel whose mod list is being queried
* @param cursor Relay cursor for forward pagination (optional)
* @param limit The maximum number of nodes to return in a single call
*/
public CommandFetchMods(ApolloClient apolloClient, String channelLogin, String cursor, Integer limit) {
super(apolloClient);
this.channelLogin = channelLogin;
this.cursor = cursor;
this.limit = limit != null ? limit : 100;
}

@Override
protected ApolloCall<FetchModsQuery.Data> getGraphQLCall() {
return apolloClient.query(
FetchModsQuery.builder()
.channelLogin(channelLogin)
.after(cursor)
.first(limit)
.build()
);
}
}
@@ -0,0 +1,49 @@
package com.github.twitch4j.graphql.command;

import com.apollographql.apollo.ApolloCall;
import com.apollographql.apollo.ApolloClient;
import com.github.twitch4j.graphql.internal.FetchVipsQuery;

public class CommandFetchVips extends BaseCommand<FetchVipsQuery.Data> {

/**
* The login name of the channel whose vip list is being queried
*/
private final String channelLogin;

/**
* Relay cursor for forward pagination (optional)
*/
private final String cursor;

/**
* The maximum number of nodes to return in a single call
*/
private final int limit;

/**
* Constructor
*
* @param apolloClient Apollo Client
* @param channelLogin The login name of the channel whose vip list is being queried
* @param cursor Relay cursor for forward pagination (optional)
* @param limit The maximum number of nodes to return in a single call
*/
public CommandFetchVips(ApolloClient apolloClient, String channelLogin, String cursor, Integer limit) {
super(apolloClient);
this.channelLogin = channelLogin;
this.cursor = cursor;
this.limit = limit != null ? limit : 100;
}

@Override
protected ApolloCall<FetchVipsQuery.Data> getGraphQLCall() {
return apolloClient.query(
FetchVipsQuery.builder()
.channelLogin(channelLogin)
.after(cursor)
.first(limit)
.build()
);
}
}

0 comments on commit b02a699

Please sign in to comment.