graphql-ethereum-address
v1.0.2
Published
Ethereum Address scalar type for GraphQL
Downloads
12
Maintainers
Readme
graphql-ethereum-address
Ethereum address scalar types for GraphQL
Quickstart
Install with yarn:
yarn add graphql-ethereum-address
Install with npm:
npm install graphql-ethereum-address
Integration to your existing GraphQL Schema
You need to add a scalar definition to your SDL type definitions and resolvers like below:
In your SDL type definitions
scalar EthereumAddress
You can also import ready-to-use type definitions like below:
import { EthereumAddressTypeDefinition } from 'graphql-ethereum-address';
const typeDefs = [
EthereumAddressTypeDefinition,
// other typeDefs
];
In your resolver map
import { EthereumAddressResolver } from 'graphql-ethereum-address';
const myResolverMap = {
EthereumAddress: EthereumAddressResolver,
Query: {
// more stuff here
},
Mutation: {
// more stuff here
},
};
Using it in your type definitions
That's it. Now you can use the scalar type in your schema definition like this:
type Wallet {
id: String
address: EthereumAddress
}
With Nexus
import { asNexusMethod } from 'nexus';
import { makeSchema } from 'nexus';
import { EthereumAddressResolver } from 'graphql-ethereum-address';
const EthereumAddressScalar = asNexusMethod(EthereumAddressResolver, 'eth');
export const Wallet = objectType({
name: 'Wallet',
definition(t) {
t.string('id');
t.eth('address');
},
});
const schema = makeSchema({ types: [EthereumAddressScalar, Wallet] });
Development
- Clone this repository
- Install dependencies using
yarn install
ornpm install
- Build the module using
yarn build
ornpm run build
- Start development server using
yarn dev
ornpm run dev