Search code examples
apigraphqlapi-designgraphql-js

Generate dynamic GraphQL Schema


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

Consider a people table with 3 columns.

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

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?


Solution

  • 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.