graphql-ethereum-address
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

graphql-ethereum-address

npm version Dependencies npm downloads code style: prettier License: MIT

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

  1. Clone this repository
  2. Install dependencies using yarn install or npm install
  3. Build the module using yarn build or npm run build
  4. Start development server using yarn dev or npm run dev

📑 License

MIT License

Package Sidebar

Install

npm i graphql-ethereum-address

Weekly Downloads

9

Version

1.0.2

License

MIT

Unpacked Size

20.4 kB

Total Files

12

Last publish

Collaborators

  • gomah