Skip to content
This repository was archived by the owner on May 26, 2022. It is now read-only.

could not add custom dateTime #16

Open
chaymag opened this issue Oct 10, 2018 · 3 comments
Open

could not add custom dateTime #16

chaymag opened this issue Oct 10, 2018 · 3 comments

Comments

@chaymag
Copy link

chaymag commented Oct 10, 2018

Hello , i'm trying to add dateTime scalar, i followed this tuto https://www.okgrow.com/posts/using-scalar-types-to-improve-graphql-schemas , i populated my seeder with data, added a dateTime field to my type and inserted some data with created_at as dateTime but when i execute npm start i get the following error " throw new Error('Type "' + typeRef.name.value + '" not found in document.');
^

Error: Type "DateTime" not found in document."
I can't figure out what causes this error.

@johnymontana
Copy link
Contributor

@chaymag could you try again now with the updated version? I've updated the version of neo4j-graphql.js used which should include support for custom scalars.

Also, we're working on adding proper DateTime support to neo4j-graphql.js soon, so once this is merged in a custom scalar won't be needed and will work out of the box with the Neo4j temporal types.

@JohnathanMaravilla
Copy link

@johnymontana,

I've updated neo4j-graphql-js to ^1.0.5 and I'm still having the same issue @chaymag originally reported while attempting to use the DateTime custom scalar within the okgrow/graphql-scalars package , as well as the issues I've outlined in issue #15.

@mikejoconnor
Copy link

mikejoconnor commented Mar 24, 2019

This is due to the starter using makeAugmenentedSchema() where the install instructions for DateTime are using makeExecutableSchema.

After spending more time on this than I care to admit, I have it working. Here is my index.js

import { ApolloServer, makeExecutableSchema } from "apollo-server";
import { v1 as neo4j } from "neo4j-driver";
import { makeAugmentedSchema, augmentTypeDefs } from "neo4j-graphql-js";
import dotenv from "dotenv";

import { DateTime, DateTimeScalar} from "@okgrow/graphql-scalars"

// set environment variables from ../.env
dotenv.config();

/*
 * Create an executable GraphQL schema object from GraphQL type definitions
 * including autogenerated queries and mutations.
 * Optionally a config object can be included to specify which types to include
 * in generated queries and/or mutations. Read more in the docs:
 * https://grandstack.io/docs/neo4j-graphql-js-api.html#makeaugmentedschemaoptions-graphqlschema
 */


const schema = makeExecutableSchema({
  typeDefs: [
    DateTimeScalar, augmentTypeDefs(typeDefs)
  ],
  resolverValidationOptions: {
    requireResolversForResolveType: false
  },
  resolvers: {
    DateTime,
  },
});

const augmentedSchema = makeAugmentedSchema({
  schema: schema,
  //typeDefs: typeDefs

});

/*
 * Create a Neo4j driver instance to connect to the database
 * using credentials specified as environment variables
 * with fallback to defaults
 */
const driver = neo4j.driver(
  process.env.NEO4J_URI || "bolt://localhost:7687",
  neo4j.auth.basic(
    process.env.NEO4J_USER || "neo4j",
    process.env.NEO4J_PASSWORD || "neo4j"
  )
);

/*
 * Create a new ApolloServer instance, serving the GraphQL schema
 * created using makeAugmentedSchema above and injecting the Neo4j driver
 * instance into the context object so it is available in the
 * generated resolvers to connect to the database.
 */
const server = new ApolloServer({
  context: { driver },
  schema: augmentedSchema
});

server.listen(process.env.GRAPHQL_LISTEN_PORT, "0.0.0.0").then(({ url }) => {
  console.log(`GraphQL API ready at ${url}`);
});

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

No branches or pull requests

4 participants