生成动态GraphQL模式 [英] Generate dynamic GraphQL Schema

查看:92
本文介绍了生成动态GraphQL模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个系统,其中没有.表中的列数不固定.我会举例说明.

I'm creating a system where the no. of columns in a table is not fixed. I'll explain with an example.

考虑包含3列的人员表.

Consider a people table with 3 columns.

people
----------
id | name | email

此表将向GraphQL API公开,我可以查询该表.在我的系统中,用户将能够将自定义列添加到人员表.假设他们添加了国籍"列.当他们这样做时,国籍将在API中不可用,因为在架构中未定义国籍.

This table will be exposed to a GraphQL API and I can query the table. In my system, the user will be able to add custom columns to the people table. Let's say they add a nationality column. When they do this, the nationality won't be available in the API because it is not defined in the Schema.

那么,如何使我的模式动态化,从而允许用户使用添加的每个额外列来查询人员表?

So how can I make my schema dynamic that allows the user to query the people table with every extra column they add?

推荐答案

我可以查询information_schema表或fields表并获取people表的额外字段,然后使用GraphQLObjectType来构建我的架构,而不是使用SDL

I can query the information_schema table or a fields table and get the extra fields for the people table and then use the GraphQLObjectType to build out my schema rather than using SDL.

这篇关于生成动态GraphQL模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆