Skip to content
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

Cruddl with Typescript project #91

Closed
robross0606 opened this issue Aug 29, 2019 · 12 comments
Closed

Cruddl with Typescript project #91

robross0606 opened this issue Aug 29, 2019 · 12 comments

Comments

@robross0606
Copy link

Having a heckuva time even following your demo/setup code in the Readme due to Typescript errors on cruddl dependencies. Getting errors such as:

node_modules/graphql-yoga/dist/types.d.ts:8:29 - error TS2307: Cannot find module 'apollo-server-core'.
8 import { LogFunction } from 'apollo-server-core';

I've tried mucking with my tsconfig.json and importing several different @types/ to my package.json to no avail. What am I missing?

@robross0606
Copy link
Author

robross0606 commented Aug 29, 2019

My dependencies currently look like this:

  "dependencies": {
    "chalk": "^2.4.2",
    "cruddl": "^1.0.2",
    "dotenv": "^8.0.0",
    "graphql-yoga": "^1.18.3",
    "merge-graphql-schemas": "^1.7.0"
  },
  "devDependencies": {
    "@types/jest": "^24.0.18",
    "@types/node": "^12.7.2",
    "@types/ws": "^6.0.3",
    "@typescript-eslint/eslint-plugin": "^2.0.0",
    "@typescript-eslint/parser": "^2.0.0",
    "cross-env": "^5.2.0",
    "eslint": "^6.2.2",
    "eslint-config-prettier": "^6.1.0",
    "jest": "^24.9.0",
    "nodemon": "^1.19.1",
    "prettier": "^1.18.2",
    "rimraf": "^3.0.0",
    "ts-jest": "^24.0.2",
    "ts-node": "^8.3.0",
    "typescript": "^3.5.3"
  }

@itsezc
Copy link

itsezc commented Aug 29, 2019

Try running npm i apollo-server-core

@robross0606
Copy link
Author

If that is required, shouldn't it be a dependency of cruddl or graphql-yoga?

@itsezc
Copy link

itsezc commented Aug 29, 2019

It should be however I think graphql-yoga requires an older version/package of Apollo Server afaik (which is no longer updated), I don't use yoga, I use apollo server directly

import { ApolloServer } from 'apollo-server'

const ORM = new ApolloServer({
	schema,
	onHealthCheck: () => {
		return new Promise((resolve, reject) => {
			if (true) {
				resolve()
			} else {
				reject()
			}
		})
	},
})

ORM
	.listen({
		port: 8081
	})
	.then((info) => {
		console.log(`ORM server started on http://localhost:${info.port}`)
	})

The schema here being the schema generated by Cruddl, works perfectly (:

@robross0606
Copy link
Author

I did that anyway, and got another error:

node_modules/graphql-yoga/dist/types.d.ts:8:10 - error TS2305: Module '"../../../../../../../Code/learning/graphql/cruddl/node_modules/apollo-server-core/dist"' has no exported member 'LogFunction'.

8 import { LogFunction } from 'apollo-server-core';

@itsezc
Copy link

itsezc commented Aug 29, 2019

I did that anyway, and got another error:

node_modules/graphql-yoga/dist/types.d.ts:8:10 - error TS2305: Module '"../../../../../../../Code/learning/graphql/cruddl/node_modules/apollo-server-core/dist"' has no exported member 'LogFunction'.

8 import { LogFunction } from 'apollo-server-core';

Yup, as expected it was the apollo-server-core package not being installed, your best bet is using the code I provided above, and here's the rest to generate the schema:

import { ArangoDBAdapter, Project as ProjectConfiguration } from 'cruddl'
import DataModel from './schema.graphql'

const Database = new ArangoDBAdapter({
	databaseName: '',
	url: '',
	user: '',
	password: ''
})

const Project = new ProjectConfiguration({
	sources: [
		{
			name: 'schema.graphql',
			body: DataModel
		},
		{
			name: 'permission-profiles.json',
			body: JSON.stringify({
				permissionProfiles: {
					default: {
						permissions: [
							{
								roles: ['admin'],
								access: 'readWrite'
							},
							{
								roles: ['user*'],
								access: 'read'
							}
						]

					}
				}
			})
		}
	],
	getExecutionOptions: ({ context }) => ({ authRoles: ['users'] })
})

const schema = Project.createSchema(Database)
Database.updateSchema(Project.getModel())

@robross0606
Copy link
Author

@itsezc have you seen any strange issues with response caching when using Apollo like this? All my responses are getting cached on a per-client basis, including mutations. It is really strange behavior to cache mutation responses by default. I literally cannot execute more than one record insertion using the same query in a row without restarting the server.

@itsezc
Copy link

itsezc commented Aug 29, 2019

@robross0606 I have never seen that happen to me, with or without Cruddl

I still had a look into Apollo Server caching and the closet thing I could find was:
https://www.apollographql.com/docs/apollo-server/features/caching/#saving-full-responses-to-a-cache

@robross0606
Copy link
Author

@itsezc, I'm absolutely baffled by this behavior. I opened a new ticket (#92) to discuss. I'm seeing similar behavior across multiple different GraphQL client test tools (Insomnia, Playground, etc.). Since cruddl is all auto-wired I can't even figure out where to put a breakpoint or control log output to tell what's happening.

@Yogu
Copy link
Member

Yogu commented Aug 30, 2019

I think we can just switch to ApolloServer. graphql-yoga has caused quite a few headaches by just trying to update it a few times...

@robross0606
Copy link
Author

Agreed. A version of suggestions from @itsezc worked fine for me.

@robross0606
Copy link
Author

This has been addressed on #95

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

3 participants