Coder Social home page Coder Social logo

Comments (3)

migueloller avatar migueloller commented on May 18, 2024

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.

serle avatar serle commented on May 18, 2024

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.

migueloller avatar migueloller commented on May 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

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

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.