当前位置: 首页 > 工具软件 > graphql-cli > 使用案例 >

express-cli_GraphQL-Express-App CLI-学习和构建GraphQL API的新方法

锺离德运
2023-12-01

express-cli

Hey guys, if you are new to OSS(open source software) development and want to get started with open source contributions, then here is the organization for you where you can initiate your projects and contribute to previously started projects too!

大家好,如果您是OSS(开源软件)开发的新手,并且想开始进行开源贡献,那么这里是您的组织,您可以在其中启动项目并为以前开始的项目做出贡献!

Ping me on Twitter if you would like to start a Project in QuBytes-OSS!

如果您想在QuBytes-OSS中启动项目,请在Twitter上向我发送消息!

Organization Link: https://github.com/QuBytes-OSS

组织链接: https : //github.com/QuBytes-OSS

I have been using GraphQL to learn and build some personal projects. And in the process, I needed some boilerplate to a new project.

我一直在使用GraphQL学习和构建一些个人项目。 在此过程中,我需要为新项目提供一些样板。

It inspired me to start working on something that would fasten the process of starting a new project. Something that enables anyone to build a GraphQL-Express server with a MongoDB database with ease.

它激发了我开始从事一些可以加快启动新项目的过程的工作。 它使任何人都可以轻松地使用MongoDB数据库构建GraphQL-Express服务器。

So, I built the graphql-express-app CLI tool that can be used by anyone to start their new GraphQL-Express project with a MongoDB database.

因此,我构建了graphql-express-app CLI工具,任何人都可以使用它来启动一个具有MongoDB数据库的新GraphQL-Express项目。

特征: (Features:)

  1. Command Line Interface for faster project generation.

    命令行界面可加快项目生成速度。
  2. Initialize Git from the CLI.

    从CLI初始化Git。
  3. Install dependencies from CLI.

    从CLI安装依赖项。
  4. TypeScript Support (Coming Soon!)

    TypeScript支持(即将推出!)

What is graphql-express-app CLI?

什么是graphql-express-app CLI?

It is a CLI (command line interface) to start a GraphQL-Express server with some pre-designed MongoDB model for handling database and a Schema to access the Database and carry out GraphQL queries and mutations.

它是一个CLI(命令行界面),用于启动GraphQL-Express服务器,该服务器具有一些用于处理数据库的预先设计的MongoDB模型和用于访问数据库并执行GraphQL查询和变异的模式。

What to expect from the CLI?

CLI会有什么期望?

The CLI will lead you to create a simple GraphQL-Express app that you can further build according to your project needs.

CLI将引导您创建一个简单的GraphQL-Express应用程序,您可以根据项目需求进一步构建该应用程序。

What are the dependencies in the generated project?

生成的项目中有哪些依赖项?

This CLI is built to initialize a GraphQL-Express server. It uses the following dependencies for starting a new project.

构建此CLI是为了初始化GraphQL-Express服务器。 它使用以下依赖项来启动新项目。

  • graphql: To build a GraphQL schema and design GraphQL types and use them for creating queries and mutations.

    graphql :构建GraphQL模式并设计GraphQL类型并将其用于创建查询和变异。

  • express: It is an npm module used to build routes in back-end applications and create middleware functions.

    express :这是一个npm模块,用于在后端应用程序中构建路由并创建中间件功能。

  • express-graphql: it helps us create a GraphQL HTTP server in the Express routes as a middleware function.

    express-graphql :它帮助我们在Express路由中创建GraphQL HTTP服务器作为中间件功能。

  • graphql-type-long: GraphQL doesn’t have a predefined long-integer type. This npm module helps bridge that gap.

    graphql-type-long :GraphQL没有预定义的long-integer类型。 这个npm模块有助于弥合这一差距。

  • dotenv: used to store MongoDB URI.

    dotenv :用于存储MongoDB URI。

  • mongoose: used to connect to the MongoDB database and carry out CRUD functions.

    mongoose :用于连接到MongoDB数据库并执行CRUD功能。

How to use the graphql-express-app CLI?

如何使用graphql-express-app CLI?

Make sure to have the latest Node.js version installed and MongoDB for database.

确保已安装最新的Node.js版本以及用于数据库的MongoDB。

1.使用以下命令在您的计算机上全局安装graphql-express-app CLI: (1. Use the following command to install the graphql-express-app CLI globally on your machine:)

$ npm i -g graphql-express-app

2.根据所需名称创建一个文件夹,然后打开该文件夹: (2. Create a folder according to your desired name and open the same:)

$ mkdir folder_name && cd folder_name

3.在外壳中运行以下命令: (3. Run the following command in the shell:)

[yolo@localhost folder_name]$ graphql-express-app

4.遵循问题并回答选项。 (4. Follow the questions and answer the options.)

5.确保在您的计算机上安装了MongoDB或在线MongoDB实例,并相应地在项目中更改.env变量。 (5. Make sure to have a MongoDB installed on your machine or have an online MongoDB instance and change .env variable in the project accordingly.)

Voila! You have successfully created a GraphQL-Express App!

瞧! 您已经成功创建了GraphQL-Express应用程序!

TypeScript Support

TypeScript支持

I am currently working on TypeScript support for the CLI. Soon enough we will release the version with TypeScript support.

我目前正在为CLI提供TypeScript支持。 很快,我们将发布具有TypeScript支持的版本。

Hope you like this project and make use of it in your future projects ❤

希望您喜欢这个项目,并在以后的项目中使用它❤

Happy coding!

祝您编码愉快!

项目存储库: (Repository for the project:)

如果您将这个工具用于您的项目,请给它加星标 (Give it a star if you will use this tool for your projects)

翻译自: https://levelup.gitconnected.com/graphql-express-app-cli-a-new-way-to-learn-and-build-graphql-apis-1d1d03878b2b

express-cli

 类似资料: