惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
C
CERT Recently Published Vulnerability Notes
C
Cisco Blogs
Cloudbric
Cloudbric
The Last Watchdog
The Last Watchdog
L
LINUX DO - 热门话题
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Application and Cybersecurity Blog
Application and Cybersecurity Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Security Archives - TechRepublic
Security Archives - TechRepublic
TaoSecurity Blog
TaoSecurity Blog
V2EX - 技术
V2EX - 技术
H
Heimdal Security Blog
S
Security Affairs
L
Lohrmann on Cybersecurity
Hacker News - Newest:
Hacker News - Newest: "LLM"
Simon Willison's Weblog
Simon Willison's Weblog
WordPress大学
WordPress大学
小众软件
小众软件
Security Latest
Security Latest
AWS News Blog
AWS News Blog
Apple Machine Learning Research
Apple Machine Learning Research
GbyAI
GbyAI
Engineering at Meta
Engineering at Meta
阮一峰的网络日志
阮一峰的网络日志
罗磊的独立博客
F
Full Disclosure
S
Schneier on Security
L
LangChain Blog
MyScale Blog
MyScale Blog
Know Your Adversary
Know Your Adversary
P
Privacy International News Feed
Google Online Security Blog
Google Online Security Blog
Scott Helme
Scott Helme
Stack Overflow Blog
Stack Overflow Blog
爱范儿
爱范儿
A
Arctic Wolf
Martin Fowler
Martin Fowler
B
Blog RSS Feed
大猫的无限游戏
大猫的无限游戏
博客园 - 三生石上(FineUI控件)
The Register - Security
The Register - Security
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
博客园_首页
Latest news
Latest news
F
Fortinet All Blogs
G
GRAHAM CLULEY
T
The Exploit Database - CXSecurity.com
Hacker News: Ask HN
Hacker News: Ask HN

remy sharp's l:inks

Deno Style Guide Easy 6502 by skilldrick Profiling React.js Performance BEM Naming Cheat Sheet by 9elements Visual 6502 Remix Elijah Manor (@elijahmanor) on X All – Tiny Helpers AST explorer Insecure How to Authenticate with Next.js and Auth0: A Guide for Every Deployment Model Revealed: quarter of all tweets about climate crisis produced by bots I Add 3-25 Seconds of Latency to Every Page I Visit GitHub - ericchiang/pup: Parsing HTML at the command line Browserling – Online cross-browser testing Error Handling with GraphQL and Apollo Schwerkraftprojektionsgerät How To Turn Off Catalina Update Notifications (Prompts & Badges) • macReports Maskable.app It’s 2020 and you’re in the future Emulators written in JavaScript | Frederic Cambus The Size of Space systemfontstack JavaScript isn’t always available and it’s not the user’s fault Programming Fonts - Test Drive Screen Size Map GitHub - Yonet/MixedRealityResources: Mixed Reality related resources The Lines of Code That Changed Everything Notes from the Internet Health Report 2019 CopyPalette Generative Artistry Profile a React App for Performance nanoSQL 2 Moving Your JavaScript Development To Bash On Windows — Smashing Magazine Startup Playbook How to Release a Custom React Component, Hook or Effect as an npm Package React Suite - Enterprise React UI Component Library Use VSCode Dimmer to Highlight Code when Teaching 3 simple rules for effectively handling dates and timezones Large collection of how to animate pixelart Accessible React component libraries mineral-ui.com Australian Government Design System Reakit – Toolkit for building accessible UIs Chakra UI Curl Cookbook The problem with tooltips and what to do instead GitHub - trimstray/the-book-of-secret-knowledge: A collection of inspiring lists, manuals, cheatsheets, blogs, hacks, one-liners, cli/web tools and more. It Form design: from zero to hero all in one blog post Brussels changes its mind AGAIN on .EU domains: Euro citizens in post-Brexit Britain can keep them after all Improve Your Email Campaigns with These Fantastic Tools Ethical Web Principles Old Typewriter Text Effect Bruce Lawson Google open sources standardized code in bid to become Mr Robots.txt Preferreds-color-scheme:你好,黑暗,我的老朋友  |  Articles  |  web.dev Free for Developers Startup idea checklist Developing a Robust Font Loading Strategy for CSS-Tricks—zachleat.com How I use Slack—alone—to get more done Upcoming proposals in JavaScript 🦄 VueJS is dead, long live VueJS! Bruce Lawson Answers for young people - Tim Berners-Lee Finally, an AI that can reliably catch and undo Photoshop airbrushing. Who made it? Er, Photoshop maker Adobe Qubyte Codes - How I schedule posts using GitHub Actions Games and Graphics in Popup URL bars Stack 58 bytes of css to look great nearly everywhere The reduce ({...spread}) anti-pattern - RichSnapp.com The Online Disassembler CSS Gradient – Generator, Maker, and Background Chrome DevTools  |  Chrome for Developers HB88 | Đăng Nhập HB88 Cá Cược Nhanh Chóng Không Bị Chăn #1 Introducing React Apollo 2.1 - Apollo GraphQL Blog Color Palettes Generator and Color Gradient Tool Clément Chastagnol ~ Moving efficiently in the CLI Testing Async Components · Issue #346 · enzymejs/enzyme Game Platforms recent news | Game Developer Professional Sound Effects - Royalty-Free SFX | Unlimited Downloads entr(1) Learn React From The Comfort Of Your Browser Axe Rules | Deque University Record and share your terminal sessions, the simple way Web Design Museum Powerful New Additions to the CSS Grid Inspector in Firefox Nightly – Mozilla Hacks - the Web developer blog Latency | Apex Software HackerNoon Signals and Sine Waves (Learn Web Audio from the Ground Up, Part 1) JavaScript Systems Music Vintage bits on cassettes Microsoft Design Legal Documents & Contract Templates | Simply Docs GraphQL and MongoDB — a quick example Using GraphQL with MongoDB Your First GraphQL Server Build a GraphQL server from scratch Practical Redux, Part 3: Project Planning and Setup 架构标记测试工具 | Google 搜索中心  |  Search Central  |  Google for Developers Freesound
create-graphql-server — instantly scaffold a GraphQL server
Tom Coleman · 2017-04-07 · via remy sharp's l:inks

Feb 2018: Note this project is not actively maintained . As a scaffolding tool, this is not necessarily an issue (you can generate a project with it and then forget about the tool). A spiritual successor is the graphql-cli project. Please take a look!


GraphQL is a much-touted successor to REST pioneered by Facebook and adopted by leading organizations like GitHub, Pinterest, and Shopify. GraphQL is a great way to supercharge your app development, and as it’s just a specification, lets you use your choice of server and database technologies.

As a result, it isn’t always easy to get started quickly with a GraphQL server, especially if you are primarily a frontend developer and want to get an API together quickly and painlessly. Although example code exists to guide people on building GraphQL servers, a tool to get started quickly was missing.

As part of my work with the Apollo project, I created a tool to fit that purpose: create-graphql-server(CGS) — to help you generate a best-practice MongoDB-backed NodeJS GraphQL server with a few commands.

Here we go!

A NodeJS and MongoDB-based GraphQL server

The great thing about the GraphQL specification is that it’s agnostic of server and database technologies. When building a GraphQL endpoint you can pick any technology that best fits the project’s needs. However, this abundance of choice can be daunting if you’re just getting started. You can end up spending a disproportionate amount of time waffling when you could be writing your GraphQL schema.

CGS scaffolds a GraphQL server atop reasonable backend technologies. The combination of NodeJS and MongoDB (recommended by popular open source stacks like MEAN and MeteorJS) help the pragmatic developer use GraphQL quickly.

In practice, CGS generates NodeJS code and ships (in development) with a built-in MongoDB server. Once you create and start up a CGS app, it will start its own MongoDB server (on port 3002), and serve GraphQL on port 3000.

A code generator

CGS makes heavy use of the graphql-server library from the Apollo project, which itself uses Facebook’s graphql-js core GraphQL implementation. CGS is not a library, however. When you run a CGS command, it simply generates the code you might have written yourself to build such a server.

The idea is both to demonstrate (what we think is) best practice in building such a server, and kick-start your development without bogging you down with the scaffolding and boilerplate details.

When you inspect the generated code, hopefully it will be clear how it all works. You can modify the code, add to it, remove it and take your server to the next level. Or you can throw your CGS away and reimplement the schema with a totally different tech stack (if you are following a schema-first development process, this shouldn’t be a big problem for you!)

Using CGS

There are two commands that CGS ships with that you need to know about:

  1. create-graphql-server init MY-PROJECT — create a brand new project. This will put down all the scaffolding to get you up and running. You can just yarn; yarn start inside the created project and start running GraphiQL queries at http://localhost:3000/graphiql (or real queries at http://localhost:3000/graphql).
  2. create-graphql-server add-type Type.graphql — add a new type definition to your schema based on a input type definition. This command looks at the type specified in Type.graphql and creates both the schema type, models and resolvers needed to connect that type to a MongoDB collection, as well as a set of root queries, mutations and subscriptions to start using that type right away.

Generating a Type for your Schema

CGS inputs are written in the GraphQL schema language, decorated with some special code-generation directives.

The above input specification is all you need to get a user collection with an association to a task collection (via a ownerId field on the task record) and set of fields.

CGS will create default mutations to add, edit and remove users, as well as queries to list all users and find users by id. This enables you to get started quickly; you should add authentication to these built-in resolvers before you hit production.

Authentication

CGS also comes with an authentication system based on JSON Web Tokens built in. You can easily attach it to a type named User and get a user object available in the context to all your resolvers. You can read how to do this in the docs, or in the tutorial post that covers the subject.

Get started

You can get started using CGS for your next API right now. Just install the code generator with npm install -g create-graphql-server and you are good to go!

For more detail, check out the project page for the latest. Get an walk through for building a basic server with CGS in my article GraphQL & React tutorial part 6.