Skip to content

astFromValue: Cannot convert value to AST #73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
anhldbk opened this issue Apr 4, 2019 · 2 comments
Closed

astFromValue: Cannot convert value to AST #73

anhldbk opened this issue Apr 4, 2019 · 2 comments

Comments

@anhldbk
Copy link

anhldbk commented Apr 4, 2019

Hi guys,

I'm trying to use this beautiful library in the following code, but it throws an exception:

/Users/xxx/Works/gql/node_modules/graphql/utilities/astFromValue.js:132
          throw _iteratorError;
          ^

TypeError: Cannot convert value to AST: { key: "value" }
    at astFromValue (/Users/xxx/Works/gql/node_modules/graphql/utilities/astFromValue.js:195:11)
    at astFromValue (/Users/xxx/Works/gql/node_modules/graphql/utilities/astFromValue.js:109:26)
    at Object.<anonymous> (/Users/xxx/Works/gql/app.js:73:11)
    at Module._compile (internal/modules/cjs/loader.js:738:30)
    at loader (/Users/xxx/Works/gql/node_modules/babel-register/lib/node.js:144:5)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/xxx/Works/gql/node_modules/babel-register/lib/node.js:154:7)
    at Module.load (internal/modules/cjs/loader.js:630:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:570:12)
    at Function.Module._load (internal/modules/cjs/loader.js:562:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:801:12)

Here's the code

import { makeExecutableSchema } from 'graphql-tools';
import GraphQLJSON from 'graphql-type-json';
import {
  astFromValue,
  valueFromAST,
  isValidJSValue
} from 'graphql/utilities'

const typeDefs = `
scalar JSON

type MyType {
  extra: JSON
}

# ...
`;

const resolvers = {
  JSON: GraphQLJSON,
};

var schema = makeExecutableSchema({ typeDefs, resolvers });

var myType = schema.getType('Message'

var value = {
    extra: {'key': 'value'}
}


// THIS WILL THROW EXCEPTIONS
astFromValue(value, myType)

Would you please tell me how to fix this? Thanks in advance!

@taion
Copy link
Owner

taion commented Apr 4, 2019

That utility function doesn't support converting arbitrary scalars to AST.

@taion taion closed this as completed Apr 4, 2019
@anhldbk
Copy link
Author

anhldbk commented Apr 5, 2019

@taion thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants