Comments (3)
Hi @serle,
I just saw this issue, I apologize for the late response.
It would be possible to modify the GraphQL type after the fact, but keep in mind there's nothing stopping you from separating your type definitions from your resolvers. You could even have a MyType.graphql
file and write a small utility function that uses a .graphql
file for the type definitions and a MyType.js
file for the resolvers.
from graphql-utilities.
Thx @migueloller
I have created a small function that provides a promise to assembles all my .graphql
and .js
makes the executable GraphQL
schema. Once the promise resolves I start the GraphQL server. I ended up using the dynamic module loading functionality to load in the "resolve" javascript modules.
from graphql-utilities.
Here's a quick example of a function that does it synchronously:
/* build.js */
const utilities = require('graphql-utilities')
const fs = require('fs')
const build = (...args) =>
utilities.build(fs.readFileSync(__filename.replace(/\.js$/, '.graphql'), 'utf-8'), ...args)
You can then have the following directory structure:
/src
|-- build.js
|-- MyType.js
`-- MyType.graphql
And MyType.js
is as simple as:
const build = require('./build')
module.exports = build(/* config, typeDependencies */) // GraphQLObjectType
from graphql-utilities.
Related Issues (13)
- GraphQL Custom Types
- Explore exporting buildType and buildSchema functions
- GraphQLInputObjectType default values aren't working for non-named types (i.e., GraphQLList)
- Add support for imports
- `mapNameToValue` for GraphQL enums
- Integration Tests
- Error messages for better developer experience
- Restructure `build` for building GraphQLSchema HOT 1
- Detailed API Docs HOT 10
- Flow Type Annotations
- Inferring a schema from a Query doesn't allow config shortcut
- Expose functionality for passing custom directives HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql-utilities.