-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from smartweaver/crookse/refactor/graphql-changes
refactor(modules/graphql): use GraphQL POST request body
- Loading branch information
Showing
12 changed files
with
251 additions
and
280 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/modules/graphql/arweave.net/builders/TransactionQueryBuilder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { QueryBuilderOptions } from "../types/QueryBuilderOptions.ts"; | ||
import { QueryTransactionArgs } from "../types/Schema.ts"; | ||
import { AbstractQueryBuilder } from "./AbstractQueryBuilder.ts"; | ||
|
||
const GetTransactionOperation = `query GetTransaction( | ||
$id: ID! | ||
) { | ||
transaction(id: $id) { | ||
{{ return_schema }} | ||
} | ||
} | ||
`; | ||
|
||
export class TransactionQueryBuilder | ||
extends AbstractQueryBuilder<QueryTransactionArgs> { | ||
protected query = GetTransactionOperation; | ||
|
||
constructor(options?: QueryBuilderOptions) { | ||
super(options); | ||
this.returnSchema(` | ||
id | ||
owner { | ||
address | ||
} | ||
block { | ||
height | ||
timestamp | ||
} | ||
tags { | ||
name | ||
value | ||
} | ||
`); | ||
} | ||
|
||
build() { | ||
return { | ||
operationName: `GetTransaction`, | ||
query: this.buildQuery(), | ||
variables: this.operation_variables, | ||
}; | ||
} | ||
|
||
id(id: string) { | ||
this.operation_variables.id = id; | ||
return this; | ||
} | ||
} |
121 changes: 121 additions & 0 deletions
121
src/modules/graphql/arweave.net/builders/TransactionsQueryBuilder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import { QueryBuilderOptions } from "../types/QueryBuilderOptions.ts"; | ||
import { QueryTransactionsArgs, TagFilter } from "../types/Schema.ts"; | ||
import { AbstractQueryBuilder } from "./AbstractQueryBuilder.ts"; | ||
|
||
const GetTransactionsOperations = `query GetTransactions( | ||
$ids: [ID!] | ||
$owners: [String!] | ||
$recipients: [String!] | ||
$tags: [TagFilter!] | ||
$bundledIn: [ID!] | ||
$block: BlockFilter | ||
$first: Int = 10 | ||
$after: String | ||
$sort: SortOrder = HEIGHT_DESC | ||
) { | ||
transactions( | ||
ids: $ids | ||
owners: $owners | ||
recipients: $recipients | ||
tags: $tags | ||
bundledIn: $bundledIn | ||
block: $block | ||
first: $first | ||
after: $after | ||
sort: $sort | ||
) { | ||
{{ return_schema }} | ||
} | ||
}`; | ||
|
||
export class TransactionsQueryBuilder | ||
extends AbstractQueryBuilder<QueryTransactionsArgs> { | ||
query = GetTransactionsOperations; | ||
|
||
constructor(options?: QueryBuilderOptions) { | ||
super(options); | ||
|
||
this.returnSchema(` | ||
pageInfo { | ||
hasNextPage | ||
} | ||
edges { | ||
cursor | ||
node { | ||
id | ||
owner { | ||
address | ||
} | ||
block { | ||
height | ||
timestamp | ||
} | ||
tags { | ||
name | ||
value | ||
} | ||
} | ||
} | ||
`); | ||
} | ||
|
||
/** | ||
* @returns `this` instance for further method chaining. | ||
*/ | ||
first(first: number) { | ||
this.operation_variables.first = first; | ||
return this; | ||
} | ||
|
||
/** | ||
* @returns `this` instance for further method chaining. | ||
*/ | ||
after(after: string) { | ||
this.operation_variables.after = after; | ||
return this; | ||
} | ||
|
||
build() { | ||
return { | ||
operationName: `GetTransactions`, | ||
query: this.buildQuery(), | ||
variables: this.operation_variables, | ||
}; | ||
} | ||
|
||
/** | ||
* @returns `this` instance for further method chaining. | ||
*/ | ||
ids(ids: string[]) { | ||
this.operation_variables.ids = ids; | ||
|
||
return this; | ||
} | ||
|
||
/** | ||
* @returns `this` instance for further method chaining. | ||
*/ | ||
owners(owners: string[]) { | ||
this.operation_variables.owners = owners; | ||
|
||
return this; | ||
} | ||
|
||
/** | ||
* @returns `this` instance for further method chaining. | ||
*/ | ||
recipients(recipients: string[]) { | ||
this.operation_variables.recipients = recipients; | ||
return this; | ||
} | ||
|
||
/** | ||
* Set the tags to send with the query. | ||
* @param tags The tags in question. | ||
* @returns `this` instance for further method chaining. | ||
*/ | ||
tags(tags: TagFilter[]) { | ||
this.operation_variables.tags = tags; | ||
return this; | ||
} | ||
} |
2 changes: 0 additions & 2 deletions
2
...ules/graphql/types/QueryBuilderOptions.ts → .../arweave.net/types/QueryBuilderOptions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
export type QueryBuilderOptions = { | ||
server_url?: string; | ||
/** GraphQL query variables */ | ||
variables?: any; | ||
}; |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.