GithubHelp home page GithubHelp logo

Comments (5)

helfer avatar helfer commented on May 1, 2024 1

You can already do custom scalar types. If you define scalar MyType in the schema, and then write this in the resolvers:

{
  MyType: {
    __parseLiteral(val){ ... },
    __serialize(val){ ... },
    // etc.
  }
}

Notice the two underscores __ in front of parseLiteral etc.

I've implemented a JSON type in shorthand this way for myself, so I'm sure it works.

Let me know if that doesn't fit your needs.

from graphql-tools.

WickyNilliams avatar WickyNilliams commented on May 1, 2024 1

Sorry to jump on, but for me this doesn't work...

I am using mockServer and passing my resolvers in. I have a resolver for a custom Date scalar like so (ignoring the impl of it for now):

  Date: {
    __parseValue(value) {
      return value;
    },
    __serialize(value) {
      return value;
    },
    __parseLiteral(ast) {
      return ast.value;
    }
  }

But then I get the error:

Error: mockFunctionMap[Date] must be a function

If i make it a function I get the error:

Error: GraphQL error: Expected a value of type "Date" but received: [object Object]

from graphql-tools.

athibaud avatar athibaud commented on May 1, 2024

@helfer awesome! that definitely fits my needs :)

large up for this whole apollo project, it's a real pleasure to use. 🙏

from graphql-tools.

seeden avatar seeden commented on May 1, 2024

@helfer can you add your JSON example?

from graphql-tools.

helfer avatar helfer commented on May 1, 2024

@seeden see here: http://dev.apollodata.com/tools/graphql-tools/scalars.html

from graphql-tools.

Related Issues (20)

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.