Sample Node Native Module (for Electron) which exposes MAPI as a GraphQL endpoint
Перейти к файлу
Bill Avery 37371d0b60 Update gqlmapi to match cppgraphqlgen 2022-03-27 11:10:30 -07:00
.github/workflows Build in CI since gqlmapi is public 2021-02-10 16:57:16 -08:00
lib Fix up the module exports 2021-01-27 21:32:55 -08:00
scripts Copy the gqlmapi.dll to the package 2021-02-11 21:31:59 -08:00
src Update gqlmapi to match cppgraphqlgen 2022-03-27 11:10:30 -07:00
.gitignore Add V8_COMPRESS_POINTERS for release builds 2021-01-28 10:00:42 -08:00
CODE_OF_CONDUCT.md Initial CODE_OF_CONDUCT.md commit 2021-01-26 20:51:41 -08:00
LICENSE Initial LICENSE commit 2021-01-26 20:51:43 -08:00
README.md Fix link in README 2021-01-30 16:45:23 -08:00
SECURITY.md Initial SECURITY.md commit 2021-01-26 20:51:44 -08:00
SUPPORT.md Fill in placeholder docs 2021-01-26 23:27:40 -08:00
jest.config.js Initial commit on GitHub 2021-01-26 21:04:40 -08:00
package-lock.json Bump minimist from 1.2.5 to 1.2.6 2022-03-26 22:38:15 +00:00
package.json Bump electron from 11.5.0 to 13.6.6 2022-03-25 19:15:16 +00:00

README.md

Electron-GqlMAPI

This is a Node Native Module wrapped around GqlMAPI, built against the Electron runtime. You could build it for a different version of Node or v8 as long as it's supported in CMake.js and NAN. The core logic for binding the GqlMAPI service to the Node v8 runtime is in NodeBinding.cpp, and aside from one extra parameter in startService, it should work with any service generated using CppGraphQLGen.

This project was originally based on electron-cppgraphql, but it has many upgrades to the build process, packaging, and the implementation since then. It is not cross-platform like electron-cppgraphql (which used a trivial service with mock data), but I intend to feed these improvements back into electron-cppgraphql. For now, this is a much better starting point if you want to implement your own Node Native Module for a CppGraphQLGen service.

Getting Started

To begin, you will need to satisfy the requirements for building GqlMAPI. If you are using Vcpkg to install CppGraphQLGen and GoogleTest as suggested in those instructions, then you will also need to save an npm config setting for CMake.js to use the vcpkg.cmake toolchain file:

> npm config set cmake_CMAKE_TOOLCHAIN_FILE %VCPKG_ROOT%\scripts\buildsystems\vcpkg.cmake

Then you can build and test the module using npm:

> npm install
> npm test

Sample App

There's a sample integration with GraphiQL in eMAPI. Take a look at startElectron.js to see how you can load the native module in the main process and connect to it with Electron's IPC API from the browser process. The main index.js script in this package wraps all of that up in a startGraphQL function.

This project includes a preload.js script exposes that IPC channel as a safer and friendlier API through the contextBridge. After the preload, Electron blocks access to APIs that haven't been exported over the bridge, including IPC. The path to the preload script is exported as preloadPath from the index.js script in this package, so if you import/require it you can set that directly on the BrowserWindow webPreferences.preload property.

The index.js script loaded in the browser process puts all of that together in a fetchQuery function, which GraphiQL uses for all service communication. This is specific to the interface that GraphiQL requires, but it is similar to the way that Apollo stateless links work with promises and/or observables for subscription support. Integrating with another GraphQL client like Apollo or Relay is currently left as an exercise for the reader, but a future version will probably include reference implementations, once I have a chance to build test projects for them.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.