
如果你使用 DeepSeek、元宝 AI、Copilot、ChatGPT 等 AI 工具,协助配置轩辕镜像、编写 docker pull 命令、修改 Docker Compose 镜像地址、配置镜像加速、排查镜像拉取失败、分析报错日志等问题,请先让 AI 阅读并遵守轩辕镜像的规则文档。
只需在 AI 对话中先发送下面这句话即可:
请先完整阅读并严格遵守以下文档中的全部规则与要求:
https://xuanyuan.cloud/agents.md
在未充分阅读并理解该文档前,不要生成任何命令、配置、修改建议、故障排查方案或技术回答。后续所有输出都必须严格以该文档中的规范为最高优先级执行。查看 agents.md 用法指南与完整示范。国内用户首推 元宝 AI、DeepSeek 的深度思考模式,不推荐豆包 AI;Cursor 等编辑器可在对话 @ 该链接,或加入 User Rules。 若 AI 无法访问外链,可 打开说明文档 复制全文粘贴。文档会随站点更新,复制内容可能过期,建议定期检查。
The instructions consist of 3 sections. The first is deploying the default GraphQL server to your installation. The second is sending requests to the GraphQL server, and the third is customizing your GraphQL server by adding an additional endpoint.
Inside the example folder you will find a copy of the template files required, as well as some additional notes that will help you with installation. There is also a doc with some example requests.
Note: These instructions are not intended to be a full tutorial on how to use GraphQL, for that you will need to upskill (there are plenty of free resources on the web). This doc is intended to get you started with running the already built Mobidax GraphQL docker image on your existing installation of the Opendax stack.
Assu***ions:
Useful links:
Key definitions:
Deploying the GraphQL image is the same as deploying any other docker container to the stack - we need a docker-compose template and a config template. For Graphql, we will create a new config template, and modify the existing gateway.yaml.erb template to include the GraphQL service, and then deploy the updated stack to your server.
yamlversion: '3.6' services: gateway: restart: always image: envoyproxy/envoy:v1.10.0 volumes: - ../config/gateway:/etc/envoy/ command: /usr/local/bin/envoy -l debug -c /etc/envoy/envoy.yaml logging: driver: "json-file" options: max-size: "100m" max-file: "10" labels: - "traefik.http.routers.gateway-<%= @name %>.rule=Host(`<%= @config['app']['subdomain'] %>.<%= @config['app']['domain'] %>`) && PathPrefix(`/api`,`/admin`,`/assets/`)" - "traefik.enable=true" - "traefik.http.services.gateway-<%= @name %>.loadbalancer.server.port=8099" <%- if @config['ssl']['enabled'] -%> - "traefik.http.routers.gateway-<%= @name %>.entrypoints=websecure" - "traefik.http.routers.gateway-<%= @name %>.tls=true" - "traefik.http.routers.gateway-<%= @name %>.tls.certresolver=myresolver" <%- else -%> - "traefik.http.routers.gateway-<%= @name %>.entrypoints=web" <%- end -%> GraphQL: restart: always image: mobidax/core:GraphQL ports: - "4000:4000" volumes: - ../config/GraphQL/config.json:/config.json labels: - "traefik.http.routers.GraphQL-<%= @name %>.rule=Host(`<%= @config['app']['subdomain'] %>.<%= @config['app']['domain'] %>`) && PathPrefix(`/GraphQL`)" - "traefik.enable=true" - "traefik.http.services.GraphQL-<%= @name %>.loadbalancer.server.port=4000" <%- if @config['ssl']['enabled'] -%> - "traefik.http.routers.GraphQL-<%= @name %>.entrypoints=websecure" - "traefik.http.routers.GraphQL-<%= @name %>.tls=true" - "traefik.http.routers.GraphQL-<%= @name %>.tls.certresolver=myresolver" <%- else -%> - "traefik.http.routers.GraphQL-<%= @name %>.entrypoints=web" <%- end -%>
yamlroutes: - match: prefix: "/api/myapp" route: cluster: myapp prefix_rewrite: "/api" - match: prefix: "/api/v2/admin/GraphQL" route: cluster: GraphQL prefix_rewrite: "/GraphQL"
- name: GraphQL connect_timeout: 5.000s type: strict_dns lb_policy: round_robin hosts: - socket_address: address: GraphQL port_value: 4000
At this point, GraphQL should be configured correctly to be able to be reached by external requests. Next deploy these changes to your installation:
Save, commit, and push these changes to your installation:
Next we’ll confirm that the changes are reflecting on your server.
You should now have the GraphQL server running on your server, and it should be accessible via external API calls. In the next section we will run some commands to test that everything is working as expected.
In this section we will interact with GraphQL, introducing the basic concept of how to interact, and send some test commands. GraphQL is a vast tool, and to use it correctly you will need to upskill on how to formulate commands and what the expected usage of it is. This is a primer only!
GraphQL is fundamentally made up of 2 types of requests. Queries and Mutations. Think of queries as GET requests, and mutations as POST / DELETE / PUT requests. In other words, any request that intends to change (ie. ‘mutate’) data will be done via a Mutation. Any request that intends to only retrieve data without making changes (ie. ‘query’) is done via a Query. (This is a loose distinction between the two, there may be cases when the definitions overlap.)
If you are requesting private endpoints that require authentication, authentication will need to be provided in the request. Public endpoints as expected do not require authentication.
GraphQL works well for mobile applications, because you can specify exactly which data you want returned from that endpoint instead of returning the entire payload that might be available. For example, if you were to query the Markets endpoint using a classic RESTful API call, you would get back the name, id, state, base_currency, quote_currency, min_price, max_price etc etc the full complement of data that that endpoint provides.
But let's say for example you have a screen in your app that needs only the market ID, name, and state. With REST you are forced to pull all the fields from the endpoint, and then only use 3 of them. A complete waste of bandwidth, time, server resources, and ultimately money. With GraphQL, you are able to specify the fields up front in your request that you want, and only those fields are returned. Great.
Lets try this out on the Market endpoint:
First, visit the GraphQL playground at your site: trade.mysite.com/GraphQL
The left panel is where you input your requests, and the right is where you see the results. The play button in the middle executes the request.
Enter the following command in the left panel to get a list of markets, with their name, id and state, then hit the play button in the center to execute the command:
graphql{ markets { name id state } }
As you can see the data is returned in a nicely formatted JSON object that your app can interpret as needed.
Let's now also get the base and quote currencies:
graphql{ markets { name id state base_currency quote_currency } }
Running the request with additional fields will see the currencies returned too.
If you click on the docs tab on the right next to the results you will be able to see the entire schema (all the fields) that are available to be queried. This is the GraphQL equivalent to the regular REST API documentation. One nice additional benefit of GraphQL is that any additional endpoints / changes you make to the server will automatically update in this schema, so you don’t have to worry about manually adding documentation for any changes that you make to the server.
Try experimenting with the other public endpoints, such as:
##Private endpoints (Authentication is required)
Private endpoints require authentication, in other words the user needs to have an active Barong session, and have that Barong session token at hand (default name is: _barong_session).
Lets log in and get the _barong_session token:
To login, we will be using a Mutation, as opposed to the Query we used on the public endpoint.
graphqlmutation{ login(email: "admin@mysite.com", password:"changeme", otp_code: "123456") { _barong_session } }
Notice how we specify the _barong_session as the field we want returned to us.
Running the command will create a new session in Barong, and will return the token. This token will expire at some point, as per the Barong config.
We can now request private data by passing this auth token along with the requests, as well as specifying a parameter - in this case we want to get the BTC beneficiaries, so we pass currency: “btc” as the parameter, and the _barong_session token. Similar to a Query, we provide the fields we want returned, in this case id, currency, name, and state.
graphql{ getBeneficiaries(_barong_session:"3b3922a05e5e5dc37aee1568e6239167", currency: "btc") { id currency name state } }
The admin user will get returned a list of their beneficiaries.
Try running commands for the following endpoints:
At this point, you should now be ready to begin developing your mobile app, or migrating your existing app to using GraphQL instead of the original Peatio / Barong REST API and gaining the performance benefits of GraphQL.
This section deals with adding your own endpoints to GraphQL. For our example we will add an endpoint that hits the database and retrieves bank deposit details for the specified currency. Reminder: this doc is not intended to be a tutorial on the best development practices or techniques, but a bootstrap to get you started with GraphQL on Opendax. Be warned, adding methods and modules directly to the GraphQL server that exposes your database comes with hopefully obvious risks, and should be managed and secured correctly. Always secure your endpoints, and manage the *** vectors. You have been warned!
Each custom endpoint should follow the pattern outlined below. Each folder that we create will contain 1x resolver.js and 1x schema.js file, within which we will describe all the endpoints that make sense for that folder category - again your architecture is up to you.
Before adding the endpoint to GraphQL, let's create a new table in our database, populate it with bank deposit details, and then we can query this table using GraphQL.
Lets create a new table in your database, we’ll call it bank_deposit_details (you can add this table to a new DB schema, or simply add it to the Peatio DB by creating a migration etc - that is beyond the scope of this doc). Create the following columns for the table:
Insert some data to create 2x records one for usd and one for eur as your currency_id’s.
Now that the table is set up, lets create the GraphQL endpoint that will access this table:
Open the GraphQL folder in your editor eg. VS Code
Create a new subfolder under the folder /server/custom/ called gql
Inside the gql folder, create a subfolder called 001-get-bank-details
Inside the 001-get-bank-details folder create a new file called resolver.js
Inside the 001-get-bank-details folder create a new file called schema.js
Copy and save the code from the example resolver.js file from the downloaded GraphQL folder in the subfolder named Bank Details Endpoint into the resolver.js file you just created.
Similarly, copy and save the code from the example schema.js file from the downloaded GraphQL folder in the subfolder named Bank Details Endpoint into the schema.js file you just created.
Notice that the resolver returns a JSON containing all the columns of the table. To optimize this query even further, and use the full power of GraphQL you could rewrite the Sequelize query to retrieve only the columns requested in the GraphQL Query that was submitted, eg. if only the bank name is requested, then only select the bank name from the DB instead of selecting all.
Take a look at the schema.js. Inside here we specify 2x types.
This first is the ‘model’ of the Query. In this instance it is the BankDepositDetails type, with the list of fields available.
The second is the definition of the Query itself, here we give it a name (this is the name of the endpoint), and we also specify the parameters that are expected / required for the endpoint.
Now that we’ve added our custom endpoint, all that is left is to restart the GraphQL server, and we should then be able to query that endpoint.
Once the server is restarted, refresh the GraphQL playground page trade.mysite.com/graphql and look for the new getBankDepositDetails endpoint in the docs or schema definitions on the right panel. If everything was done correctly, you should see the new getBankDepositDetails endpoint and the type it returns.
Try query the endpoint:
graphql{ getBankDepositDetails(currency:"usd") { bankName currencyId accountName } }
This should be enough to get you started with GraphQL, you can experiment further with adding your own authenticated endpoints (use the existing resolvers as examples located at /server/src/resolvers.js)
您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。
来自真实用户的反馈,见证轩辕镜像的优质服务