Skip to content

Commit

Permalink
Merge pull request #448 from polywrap/prealpha-dev
Browse files Browse the repository at this point in the history
Prep 0.0.1-prealpha.36
  • Loading branch information
dOrgJelli authored Aug 22, 2021
2 parents a784cfc + 35f957e commit 485e588
Show file tree
Hide file tree
Showing 65 changed files with 357 additions and 1,400 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Web3API 0.0.1-prealpha.36
## Features
* Upgrade all JavaScript plugins to use the new `w3 plugin codegen` command. The command generates typings based on the GraphQL schema of the plugin. This ensures the plugin's resolvers match 1:1 with the GraphQL schema.

# Web3API 0.0.1-prealpha.35
## Bugs
* `@web3api/schema-bind`: Fix TypeScript plugin enum bindings.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.1-prealpha.35
0.0.1-prealpha.36
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
"scripts": {
"reset": "yarn clean && yarn && yarn build",
"clean": "npx rimraf ./**/node_modules ./**/build ./**/coverage ./**/.w3",
"build": "lerna run build --no-private --ignore @web3api/cli* --ignore @web3api/react && lerna run build --scope @web3api/client-js --scope @web3api/react && lerna run build --scope @web3api/cli",
"build": "yarn build:core && yarn build:plugins && yarn build:client && yarn build:cli",
"build:core": "lerna run build --no-private --ignore @web3api/*-plugin-js --ignore @web3api/cli* --ignore @web3api/react",
"build:plugins": "lerna run build --scope @web3api/*-plugin-js --concurrency 1",
"build:client": "lerna run build --scope @web3api/client-js --scope @web3api/react",
"build:cli": "lerna run build --scope @web3api/cli",
"lint": "lerna run lint --ignore @web3api/uts46-plugin-js",
"lint:fix": "lerna run lint --ignore @web3api/uts46-plugin-js -- --fix",
"lint:ci": "yarn lint",
Expand Down
3 changes: 0 additions & 3 deletions packages/cli/src/__tests__/project/invalid-web3api-1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,3 @@ query:
module:
language: wasm/assemblyscript
file: ./src/wrong/index.ts
import_redirects:
- uri: w3://ens/ethereum.web3api.eth
schema: ../../../../js/plugins/ethereum/schema.graphql
3 changes: 0 additions & 3 deletions packages/cli/src/__tests__/project/invalid-web3api-2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,3 @@ wrong_query:
module:
language: wasm/assemblyscript
file: ./src/query/index.ts
import_redirects:
- uri: w3://ens/ethereum.web3api.eth
schema: ../../../../js/plugins/ethereum/schema.graphql
3 changes: 0 additions & 3 deletions packages/cli/src/__tests__/project/web3api.docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,3 @@ modules:
query:
schema: ./src/query/schema.graphql
module: ./src/query/index.ts
import_redirects:
- uri: w3://ens/ethereum.web3api.eth
schema: ../../../../js/plugins/ethereum/schema.graphql
3 changes: 0 additions & 3 deletions packages/cli/src/__tests__/project/web3api.no-docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,3 @@ modules:
query:
schema: ./src/query/schema.graphql
module: ./src/query/index.ts
import_redirects:
- uri: w3://ens/ethereum.web3api.eth
schema: ../../../../js/plugins/ethereum/schema.graphql
3 changes: 0 additions & 3 deletions packages/cli/src/__tests__/project/web3api.wrong-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,3 @@ modules:
query:
schema: ./src/query/schema.graphql
module: ./src/query/index.ts
import_redirects:
- uri: w3://ens/ethereum.web3api.eth
schema: ../../../../js/plugins/ethereum/schema.graphql
3 changes: 0 additions & 3 deletions packages/cli/src/__tests__/project/web3api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,3 @@ query:
module:
language: wasm/assemblyscript
file: ./src/query/index.ts
import_redirects:
- uri: w3://ens/ethereum.web3api.eth
schema: ../../../../js/plugins/ethereum/schema.graphql
3 changes: 2 additions & 1 deletion packages/js/plugins/ens/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"schema.graphql"
],
"scripts": {
"build": "rimraf ./build && tsc --project tsconfig.build.json",
"build": "rimraf ./build && yarn codegen && tsc --project tsconfig.build.json",
"codegen": "npx -p @web3api/cli w3 plugin codegen",
"lint": "eslint --color --ext .ts src/",
"test": "jest --passWithNoTests --runInBand --verbose",
"test:ci": "jest --passWithNoTests --runInBand --verbose",
Expand Down
1 change: 1 addition & 0 deletions packages/js/plugins/ens/schema.graphql
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#import { Query, MaybeUriOrManifest } into UriResolver from "ens/uri-resolver.core.web3api.eth"
#import { Query } into Ethereum from "ens/ethereum.web3api.eth"

type Query implements UriResolver_Query {
tryResolveUri(
Expand Down
43 changes: 17 additions & 26 deletions packages/js/plugins/ens/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/* eslint-disable import/no-extraneous-dependencies */
import { query } from "./resolvers";
import { manifest } from "./manifest";
import { manifest, Query, Ethereum_Query } from "./w3";

import {
Client,
Plugin,
PluginPackageManifest,
PluginModules,
PluginFactory,
} from "@web3api/core-js";
import { ethers } from "ethers";
Expand Down Expand Up @@ -44,9 +43,11 @@ export class EnsPlugin extends Plugin {
return ethers.utils.isValidName(domain) && domain.indexOf(".eth") !== -1;
}

// TODO: generated types here from the schema.graphql to ensure safety `Resolvers<TQuery, TMutation>`
// https://github.com/web3-api/monorepo/issues/101
public getModules(client: Client): PluginModules {
public getModules(
client: Client
): {
query: Query.Module;
} {
return {
query: query(this, client),
};
Expand Down Expand Up @@ -104,19 +105,8 @@ export class EnsPlugin extends Plugin {
args: string[],
networkNameOrChainId?: string
): Promise<string> => {
const { data, errors } = await client.query<{
callContractView: string;
}>({
uri: "ens/ethereum.web3api.eth",
query: `query {
callContractView(
address: $address,
method: $method,
args: $args,
connection: $connection
)
}`,
variables: {
const { data, error } = await Ethereum_Query.callContractView(
{
address,
method,
args,
Expand All @@ -126,24 +116,25 @@ export class EnsPlugin extends Plugin {
}
: undefined,
},
});
client
);

if (errors && errors.length) {
throw errors;
if (error) {
throw error;
}

if (data && data.callContractView) {
if (typeof data.callContractView !== "string") {
if (data) {
if (typeof data !== "string") {
throw Error(
`Malformed data returned from Ethereum.callContractView: ${data.callContractView}`
`Malformed data returned from Ethereum.callContractView: ${data}`
);
}

return data.callContractView;
return data;
}

throw Error(
`Ethereum.callContractView returned nothing.\nData: ${data}\nErrors: ${errors}`
`Ethereum.callContractView returned nothing.\nData: ${data}\nError: ${error}`
);
};

Expand Down
69 changes: 0 additions & 69 deletions packages/js/plugins/ens/src/manifest.ts

This file was deleted.

9 changes: 5 additions & 4 deletions packages/js/plugins/ens/src/resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { EnsPlugin } from "./";
import { Query } from "./w3";

import { Client, PluginModule } from "@web3api/core-js";
import { Client } from "@web3api/core-js";

export const query = (ens: EnsPlugin, client: Client): PluginModule => ({
export const query = (ens: EnsPlugin, client: Client): Query.Module => ({
// uri-resolver.core.web3api.eth
tryResolveUri: async (input: { authority: string; path: string }) => {
tryResolveUri: async (input: Query.Input_tryResolveUri) => {
if (input.authority !== "ens") {
return null;
}
Expand All @@ -27,7 +28,7 @@ export const query = (ens: EnsPlugin, client: Client): PluginModule => ({
// Nothing found
return { uri: null, manifest: null };
},
getFile: (_input: { path: string }) => {
getFile: (_input: Query.Input_getFile) => {
return null;
},
});
3 changes: 2 additions & 1 deletion packages/js/plugins/ethereum/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"schema.graphql"
],
"scripts": {
"build": "rimraf ./build && tsc --project tsconfig.build.json",
"build": "rimraf ./build && yarn codegen && tsc --project tsconfig.build.json",
"codegen": "npx -p @web3api/cli w3 plugin codegen",
"lint": "eslint --color --ext .ts src/",
"test": "jest --passWithNoTests --runInBand --verbose",
"test:ci": "jest --passWithNoTests --runInBand --verbose",
Expand Down
23 changes: 0 additions & 23 deletions packages/js/plugins/ethereum/schema.graphql
Original file line number Diff line number Diff line change
@@ -1,26 +1,3 @@
### Web3API Header START ###
scalar UInt
scalar UInt8
scalar UInt16
scalar UInt32
scalar Int
scalar Int8
scalar Int16
scalar Int32
scalar Bytes
scalar BigInt

directive @imported(
uri: String!
namespace: String!
nativeType: String!
) on OBJECT | ENUM

directive @imports(
types: [String!]!
) on OBJECT
### Web3API Header END ###

type TxReceipt {
to: String!
from: String!
Expand Down
2 changes: 1 addition & 1 deletion packages/js/plugins/ethereum/src/__tests__/e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethereumPlugin } from "..";
import * as Schema from "../types";
import * as Schema from "../w3";

import { Web3ApiClient } from "@web3api/client-js";
import { ensPlugin } from "@web3api/ens-plugin-js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,3 @@ query:
module:
language: wasm/assemblyscript
file: ./src/query/index.ts
import_redirects:
- uri: w3://ens/ethereum.web3api.eth
schema: ../../../schema.graphql
Loading

0 comments on commit 485e588

Please sign in to comment.