{"_id":"0xql","_rev":"2-8a76af1797e62c34307f90ef773dddee","name":"0xql","dist-tags":{"latest":"1.0.0"},"versions":{"0.0.1":{"name":"0xql","version":"0.0.1","main":"./dist/index.js","types":"./dist/index.d.ts","license":"MIT","author":{"name":"john johnson","url":"johnrjj[at]gmail.com"},"scripts":{"build":"tsc","start":"yarn start:example:advanced","start:example:advanced":"node ./dist/example/advanced/index.js","start:example:basic":"node ./dist/example/basic/index.ts","dev:example:advanced":"ts-node src/example/advanced/index.ts","dev:example:basic":"ts-node src/example/basic/index.ts","test":"ts-node schemas.ts","prettier":"prettier --write '**/*.{js,ts,tsx,jsx}' --ignore-path .gitignore","graphql-codegen":"graphql-codegen --config codegen.yml"},"devDependencies":{"@graphql-codegen/cli":"^1.7.0","@graphql-codegen/introspection":"1.7.0","@graphql-codegen/typescript":"1.7.0","@graphql-codegen/typescript-resolvers":"1.7.0","@types/graphql":"^14.5.0","@types/lodash":"^4.14.138","@types/uuid":"^3.4.5","@types/web3":"^1.0.19","@types/ws":"^6.0.3","apollo-server-express":"^2.9.3","prettier":"^1.18.2","ts-node":"^8.3.0","typescript":"^3.6.2"},"dependencies":{"0x.js":"^7.0.1","@0x/assert":"^2.1.5","@0x/connect":"^5.0.18","@0x/json-schemas":"^4.0.1","@0x/order-utils":"^8.3.1","@0x/types":"^2.4.2","apollo-link-ws":"^1.0.18","apollo-server":"^2.9.3","graphql":"^14.5.4","graphql-subscriptions":"^1.1.0","graphql-tools":"^4.0.5","graphql-type-json":"^0.3.0","lodash":"^4.17.15","reconnecting-websocket":"^4.2.0","subscriptions-transport-ws":"^0.9.16","uuid":"^3.3.3","web3":"^1.2.1","ws":"^7.1.2"},"gitHead":"85aa59a5c5401d093460b6b798a7334edffdb737","description":"Instantly add GraphQL support to a 0x Relayer that follows the [0x Standard Relayer API](https://github.com/0xProject/standard-relayer-api) spec.","_id":"0xql@0.0.1","_nodeVersion":"10.16.2","_npmVersion":"6.9.0","dist":{"integrity":"sha512-PBr7dTyBxa0l25vCMFnbaN9d7c+H16flp4XxzxLg3uiH6Dtoz0KlezX8yX3DJULqidb/ikCs5jS3aXbfsRu9/Q==","shasum":"b2160edf116b4a238c726f0d391f5ec7dbe85b18","tarball":"https://registry.npmjs.org/0xql/-/0xql-0.0.1.tgz","fileCount":17,"unpackedSize":90165,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdd1HCCRA9TVsSAnZWagAANaMP/R+4r/IYQWI7ZgKvr8Na\nSttsj9W6hR6bGsKmmguY6QQ5uOcocj8yEkXNfx3HmoYbjNXDHAhknhQGOxOK\nBxSSzOhWEJeJFz9hMfIv/xgji3U5GvriR/IgrBqJqTJI+gTc+SfonL++d5pD\nPxp9Q/+H0w7aoQz+zr3dTJ505X+UP2sHEulq2a4RinOW6VEeDIS6oQ6xi0uS\nI/xZB/BXX2oV+DDIbWMb9sifxuLZxWwf4K2tv7QtO1EV9gETiegm5ZXSV6tt\nKxfQijaNoWe5JRgTLlpI7h3NirFRWRQbQg+TYjnE6UKFq5AlFY/d11sZ7eT3\nXqT99cNy2HCEdRyfDDkdSAK4M/rVfWZl4joDx586/aozbMSR8VFmaf4va4ek\nhEdwVHxIeYKhxfeEJfUQfgAcbZhII0YlYQHaLZc7Z5MCVcokI2UFOYlJSHaU\n7IHlLr0JQhJ6HlZyveK/nfod+qjvaUQutYMawPzDScIEeIj/ldxQn66XtSGK\nCx5X+kZJl3bpRmBOtWNSaEtEg0dW2g+NcPv7aLaUaQbouNSBVRvxP8SbjM86\nu2AU0uijfRQhYAGBy3BVwIW1cF1wNBEtGarIjXSmhJJNE4cPQ0gHoK+KG638\nWQ6+UhrnXKsE5kgFi+sS/UxpmEUwbZvplVD/OdkIOF89qAjNbFafI+uhwd0q\ndrHA\r\n=6Hv0\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDGNi3gnZivOBPU5tG8KvVx28jpqfdfU4+A6CJl/Wfg4gIhAJbWC4RQ/S0HVZ+xPTD50P9XSlPBxk1ks9zU46577d6D"}]},"maintainers":[{"name":"johnrjj","email":"johnrjj@gmail.com"}],"_npmUser":{"name":"johnrjj","email":"johnrjj@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/0xql_0.0.1_1568100801500_0.5236999889701357"},"_hasShrinkwrap":false},"1.0.0":{"name":"0xql","version":"1.0.0","main":"./dist/index.js","types":"./dist/index.d.ts","license":"MIT","author":{"name":"john johnson","url":"johnrjj[at]gmail.com"},"scripts":{"build":"tsc","start":"yarn start:example:advanced","start:example:advanced":"node ./dist/example/advanced/index.js","start:example:basic":"node ./dist/example/basic/index.ts","start:example:basic-with-subscriptions":"node ./dist/example/basic-with-subscriptions/index.ts","dev:example:advanced":"ts-node src/example/advanced/index.ts","dev:example:basic":"ts-node src/example/basic/index.ts","dev:example:basic-with-subscriptions":"ts-node src/example/basic-with-subscriptions/index.ts","test":"ts-node schemas.ts","prettier":"prettier --write '**/*.{js,ts,tsx,jsx,md}' --ignore-path .gitignore","graphql-codegen":"graphql-codegen --config codegen.yml","prepublishOnly":"yarn build"},"devDependencies":{"@graphql-codegen/cli":"^1.7.0","@graphql-codegen/introspection":"1.7.0","@graphql-codegen/typescript":"1.7.0","@graphql-codegen/typescript-resolvers":"1.7.0","@types/graphql":"^14.5.0","@types/lodash":"^4.14.138","@types/uuid":"^3.4.5","@types/web3":"^1.0.19","@types/ws":"^6.0.3","apollo-server-express":"^2.9.3","prettier":"^1.18.2","ts-node":"^8.3.0","typescript":"^3.6.2"},"dependencies":{"0x.js":"^7.0.1","@0x/assert":"^2.1.5","@0x/connect":"^5.0.18","@0x/json-schemas":"^4.0.1","@0x/order-utils":"^8.3.1","@0x/types":"^2.4.2","apollo-link-ws":"^1.0.18","apollo-server":"^2.9.3","graphql":"^14.5.4","graphql-subscriptions":"^1.1.0","graphql-tools":"^4.0.5","graphql-type-json":"^0.3.0","lodash":"^4.17.15","reconnecting-websocket":"^4.2.0","subscriptions-transport-ws":"^0.9.16","uuid":"^3.3.3","web3":"^1.2.1","ws":"^7.1.2"},"description":"Easily add GraphQL support to any 0x Relayer that follows the [0x Standard Relayer API](https://github.com/0xProject/standard-relayer-api) spec.","_id":"0xql@1.0.0","dist":{"shasum":"0ce8e792ff0b8b06b2f5e921a42cfca225813881","integrity":"sha512-5DcjM89uD/aJhbC7/Jk/yqtASWTKtXcnTsp4qGoI5LiwIAsmxJOTwOyiRxw9MsUlMXpeE9uuoho0gQdi8x8Yyw==","tarball":"https://registry.npmjs.org/0xql/-/0xql-1.0.0.tgz","fileCount":25,"unpackedSize":107568,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdeKmcCRA9TVsSAnZWagAAJRUP/R2kBvvCG8CgFZYxfuQ9\nh+xTMyfPpTu6KKu3EHVmdFRDWu3TfwIvjo9UYixZKrWn5jTeADTib2rdQ4Nv\njhS6ELQFr6WwImDOPVAdVHqywJebCcyTT7EbLT3rs7C66jHvb/4Lx5RTiqMM\nHlf+yDV4QKzV8zNZ4K9rvbI1r9hgWwox8fsrFwWyGEr+ocfS2No5nEtsqVKL\nvmMVpaA/APXEvaQxxX5x1y7XKU7xmMxnuGQknFUBXpb6o5mcRg5Ro8vgbCpD\nXfNEt5PSW8iDW0Kpgx18kY0s72Z/JSVWkPy5zg/5iB7GpFDWz6nThERgO8J/\nM9arhK+6vlIVUxm5ECV4mo74ilTEqpjjCM/ZwhM3mWpA0dBInTNoE4YehIGj\na/CwF1EJtGxhv1I/FfVSP3bRUUVWhGIbBp59qEKKuJ2po6P5WK9Aj+10MWPm\nog6sDOgWL6FsrWdCS8A27hKDQnZOqrF1i4digOEqiKAp5zT82hbzFcJlelvP\nwiECSXx0/Zm18lcoguyfuGIrZxxdWNaB/G7Peuds5+0Lf+Rwu0ck9Ttv6C0V\ng6wZYIC8NN6AKW7Zd7NHxTDJvABATlEenUsq1d55fgOpKBDcCisgPK0Y2zWz\nrs5plxs03xAqe3eZf4XuH50K/zCyxc8TkFp2ifHpTudiXGwrtSt5fuJf/LBI\neDx3\r\n=TeKr\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIG2oYSbTMPzjloIvDHyfXuFPCSyFemJT2EukjRQBIa5LAiEAuz+DsS5O4nGxdsj/73WJmDuEo+KFYAQRa/ln0m/98L0="}]},"maintainers":[{"name":"johnrjj","email":"johnrjj@gmail.com"}],"_npmUser":{"name":"johnrjj","email":"johnrjj@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/0xql_1.0.0_1568188828094_0.16328197220423935"},"_hasShrinkwrap":false}},"time":{"created":"2019-09-10T07:33:21.499Z","0.0.1":"2019-09-10T07:33:21.662Z","modified":"2022-04-04T10:09:00.410Z","1.0.0":"2019-09-11T08:00:28.205Z"},"maintainers":[{"name":"johnrjj","email":"johnrjj@gmail.com"}],"description":"Easily add GraphQL support to any 0x Relayer that follows the [0x Standard Relayer API](https://github.com/0xProject/standard-relayer-api) spec.","author":{"name":"john johnson","url":"johnrjj[at]gmail.com"},"license":"MIT","readme":"# `0xQL` (ZeroEx GraphQL)\n\nEasily add GraphQL support to any 0x Relayer that follows the [0x Standard Relayer API](https://github.com/0xProject/standard-relayer-api) spec.\n\n## Demo\n\nCheck out the GraphiQL playground here. Try creating some queries, mutations, or subscriptions.\n\nCheck out the [getting started guide](#getting-started) for a sample query and [sample subscription](#subscriptions-demo) to try out on the demo playground.\n\n## Overview\n\n`0xQL` enables developers to quickly build a GraphQL server that can automatically integrate with an existing 0x Relayer. The GraphQL server mirrors functionality of the 0x Relayer's REST and WS API, but instead can be accessed via GraphQL's [Queries](https://graphql.org/learn/queries/), [Mutations](https://graphql.org/learn/queries/#mutations), and [Subscriptions](https://graphql.org/blog/subscriptions-in-graphql-and-relay/).\n\n## Getting Started\n\n### Prerequisite\n\n- `>= Node v10`\n- `>= Yarn v1.5`\n\n### Installation\n\n```bash\nyarn add 0xql\n```\n\n## Quick Start Guide\n\nThis guide will walk through setting up a 0xQL GraphQL server that works with [RadarRelay](https://radarrelay.com/).\n\nInstall the dependencies\n\n```\n$ yarn add 0xql apollo-server\n```\n\nCreate an index.js file\n\n```bash\n$ touch index.js\n```\n\nAdd the following code to `index.js`\n\n```ts\n// index.js\nconst { ApolloServer } = require('apollo-server')\nconst { createReadyToUseResolvers, typeDefs } = require('0xql')\n\nconst APP_PORT = 4000\nconst REST_API_ENDPOINT = 'https://api.radarrelay.com/0x/v2'\n\nconst {\n  queryResolver,\n  mutationResolver,\n  jsonResolver,\n} = createReadyToUseResolvers(REST_API_ENDPOINT)\n\nconst resolvers = {\n  Query: queryResolver,\n  Mutation: mutationResolver,\n  JSON: jsonResolver,\n}\n\nconst server = new ApolloServer({\n  typeDefs,\n  resolvers,\n})\n\n// Start the GraphQL server\nserver.listen({ port: APP_PORT }, () =>\n  console.log(\n    `🚀 Server ready at http://localhost:${APP_PORT}${server.graphqlPath}`\n  )\n)\n```\n\nFinally, start the server\n\n```\nnode index.js\n```\n\nIf everything worked, you should see the following printed in the console\n\n```bash\n🚀 Server ready at http://localhost:4000/\n```\n\nCongrats, you have your own functional 0xQL GraphQL instance pointed at RadarRelay. Let's try it out!\n\nNavigate to [`http://localhost:4000`](http://localhost:4000) to check out the GQL playground\n\nTry a sample query:\n\n```gql\nquery GetOrders {\n  orders {\n    records {\n      order {\n        makerAssetData\n        makerAssetAmount\n        takerAssetData\n        takerAssetAmount\n      }\n    }\n    total\n    page\n    perPage\n  }\n}\n```\n\n### Adding Subscriptions\n\nIn addition to fetching data using queries and modifying data using mutations, the GraphQL spec supports a third operation type, called subscription. GraphQL subscriptions are a way to push data from the server to the clients that choose to listen to real time messages from the server.\n\nIf you're looking to add subscriptions, check out the implementation example [here](./src/example/basic-with-subscriptions/index.ts) which builds on the server we just made.\n\n#### Subscriptions Demo\n\nCheck out the [demo site]() for a live demo.\n\nHere's a sample subscription to send to the GraphQL server:\n\n```gql\nsubscription SubscribeToAllOrders {\n  subscribeToOrders(type: subscribe, channel: orders, requestId: \"1234\") {\n    payload {\n      order {\n        makerAddress\n        makerAssetData\n        takerAddress\n        makerAssetAmount\n        takerAssetData\n        takerAssetAmount\n        signature\n        expirationTimeSeconds\n      }\n    }\n  }\n}\n```\n\nYou'll start to get a stream of incoming orders that look like the structure you just requested:\n\n```json\n{\n  \"data\": {\n    \"subscribeToOrders\": {\n      \"payload\": [\n        {\n          \"order\": {\n            \"makerAddress\": \"0x50f84bbee6fb250d6f49e854fa280445369d64d9\",\n            \"makerAssetData\": \"0xf47261b00000000000000000000000000f5d2fb29fb7d3cfee444a200298f468908cc942\",\n            \"takerAddress\": \"0x0000000000000000000000000000000000000000\",\n            \"makerAssetAmount\": \"35003789556299530000000\",\n            \"takerAssetData\": \"0xf47261b0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2\",\n            \"takerAssetAmount\": \"6609708813064056613\",\n            \"signature\": \"0x1b37b290a52a5afccf8c9eb155b37dad510aad8b37a607b939ef6c72b73bc86d956d53dd6bc8c910d8f0d28f6fa94b567151a24dedd3d83404eea67684e348481003\",\n            \"expirationTimeSeconds\": \"1568183099\"\n          }\n        }\n      ]\n    }\n  }\n}\n```\n\n### More examples\n\n- [Basic](./src/examples/basic/index.ts) (without subscriptions)\n- [Basic](./src/examples/basic-with-subscriptions/index.ts) (with subscriptions)\n- [Advanced](./src/examples/advanced/index.ts) (demos integration with existing express server)\n\n### Client Side Integration\n\nHere's an example of integrating React and React Hooks with the 0xQL server. This assumes a React app already exists (you can always use `create-react-app` to bootstrap your app).\n\nWe're going to use the popular GraphQL library `Apollo` which offers smooth integration with React. Apollo offers a set of React Hooks which we can consume directly inside our components.\n\n#####\n\nFirst, set up the code, which includes importing the required code and setting up your first query.\n\n```\nyarn add apollo-boost @apollo/react-hooks graphql\n```\n\n```ts\nimport gql from 'graphql-tag'\nimport { useQuery } from '@apollo/react-hooks'\n\nconst GET_ORDERS_SUMMARY = gql`\n  {\n    orders {\n      records {\n        order {\n          makerAssetData\n          makerAssetAmount\n          takerAssetData\n          takerAssetAmount\n        }\n      }\n      total\n      page\n      perPage\n    }\n  }\n`\n```\n\nNow let's write our React component\n\n```tsx\nfunction Orders({ onOrderSelected }) {\n  const { loading, error, data } = useQuery(GET_ORDERS_SUMMARY);\n\n  if (loading) return 'Loading...';\n  if (error) return `Error! ${error.message}`;\n\n  return (\n    <div>\n      {data.orders.records.map(order) => (\n        <div onClick={() => onOrderSelected && onOrderSelected(order)}>\n          {order.makerAssetData}\n        </div>\n      )}\n    </div>\n  );\n}\n```\n\nThen finally, let's wrap the component in an App and a GraphQL provider:\n\n```tsx\nimport React from 'react'\nimport ApolloClient from 'apollo-boost'\nimport { render } from 'react-dom'\nimport { ApolloProvider } from '@apollo/react-hooks'\n\nconst client = new ApolloClient({ uri: 'http://localhost:4000' })\n\nconst App = () => (\n  <ApolloProvider client={client}>\n    <Orders onOrderSelected={order => console.log('order selected', order)} />\n  </ApolloProvider>\n)\n\nrender(<App />, document.getElementById('root'))\n```\n\nThat's it!\n\n## API\n\n### Available Imports\n\n- `typeDefs`\n- `createReadyToUseResolvers`\n- `resolvers`\n\n---\n\n`typeDefs` - This is the Type Definitions for the GraphQL schema\n\n`createReadyToUseResolvers` - A factory function to create opinionated, ready-to-use resolvers, and if requested, sets up websockets automatically.\n\n```ts\ninterface SubscriptionConfiguration {\n  autoSubscribe?: boolean\n  websocketUrl?: string\n  ordersTopic?: string\n  pubsub?: PubSub\n}\n\nconst resolvers = createReadyToUseResolvers(\n  relayerRestApiUrl: string,\n  customSubscriptionConfig: SubscriptionConfiguration\n):\n```\n\n**Returns:** Object that contains the following:\n\n- queryResolver\n- mutationResolver\n- subscriptionResolver\n- jsonResolver\n\nSee the `basic` example on the usage here.\n\n`resolvers`: More advanced fine-grained, less opinionated configuration over resolvers than `createReadyToUseResolvers` provides. See the `advanced` example on usage.\n\n## FAQ\n\n### What's GraphQL?\n\nGraphQL is a query language for APIs that enables declarative data fetching in order to give the client the power to specify exactly the data that is needed from the API.\n\n### What's 0x?\n\nAn open protocol for decentralized exchange on the Ethereum blockchain.\n\n### What's `0xQL`\n\nA package that provides primitives and tooling for building GraphQL support into your 0x Relayer.\n\n### How does this package apply to GraphQL?\n\nThis package, `0xQL`, provides the necessary GraphQL bindings, resolvers, schema, and types. We also include an optional opinionated setup with most things preconfigured.\n\n### How does this package apply to 0x?\n\nThe [0x Standard Relayer API](https://github.com/0xProject/standard-relayer-api) dictates a standard interface for both REST and WebSocket interaction for a relayer. Since this interface is standardized across relayers, we can also add support for GraphQL in a consistent and robust way. This package supports GraphQL queries, mutations, and subscriptions.\n\n### Sounds good, but how do I use this?\n\nThis package provides various ways to consume the `0xQL` package, depending on your level of configuration required. For example, `0xQL` supports:\n\n- Creating a standalone GraphQL server with minimal configuration. Check out the [basic example here](./src/example/basic/index.ts).\n\n- If you already have an express server and want to add GraphQL support, you can layer in GraphQL quite easily. Check out the [advanced example here](./src/example/advanced/index.ts)\n\n- If you already have a GraphQL API and you want to add 0x relayer support, you can take the `0xQL` schema and types and stich it together with your own existing GraphQL schema. (See Apollo docs for guides on schema stiching and federated GraphQL support)\n\n### Why write this package?\n\nWhy not?\n\nHaving more ways and to interact and integrate with 0x relayers is a win for the ecosystem.\n","readmeFilename":"README.md"}