apollographql / federation-demo

Federation 2 supersedes this demo and this example is no longer the newest. See https://www.apollographql.com/docs/federation/ for migration steps!
https://www.apollographql.com/docs/federation/
MIT License
503 stars 197 forks source link

Doesn't start up on 'npm run start-services' [Solved in Pull Req #74] #73

Closed julianwagle closed 1 year ago

julianwagle commented 2 years ago

Environment: MacOS Node Version 14.17.6

Full error log:

> federation-demo@ start-services /Users/home/@DEV/federation-demo
> concurrently "npm:start-service-*"

[start-service-accounts] 
[start-service-accounts] > federation-demo@ start-service-accounts /Users/home/@DEV/federation-demo
[start-service-accounts] > nodemon services/accounts/index.js
[start-service-accounts] 
[start-service-products] 
[start-service-products] > federation-demo@ start-service-products /Users/home/@DEV/federation-demo
[start-service-products] > nodemon services/products/index.js
[start-service-products] 
[start-service-reviews] 
[start-service-reviews] > federation-demo@ start-service-reviews /Users/home/@DEV/federation-demo
[start-service-reviews] > nodemon services/reviews/index.js
[start-service-reviews] 
[start-service-inventory] 
[start-service-inventory] > federation-demo@ start-service-inventory /Users/home/@DEV/federation-demo
[start-service-inventory] > nodemon services/inventory/index.js
[start-service-inventory] 
[start-service-accounts] [nodemon] 2.0.15
[start-service-accounts] [nodemon] to restart at any time, enter `rs`
[start-service-accounts] [nodemon] watching path(s): *.*
[start-service-accounts] [nodemon] watching extensions: js,mjs,json
[start-service-accounts] [nodemon] starting `node services/accounts/index.js`
[start-service-products] [nodemon] 2.0.15
[start-service-reviews] [nodemon] 2.0.15
[start-service-products] [nodemon] to restart at any time, enter `rs`
[start-service-products] [nodemon] watching path(s): *.*
[start-service-products] [nodemon] watching extensions: js,mjs,json
[start-service-reviews] [nodemon] to restart at any time, enter `rs`
[start-service-products] [nodemon] starting `node services/products/index.js`
[start-service-reviews] [nodemon] watching path(s): *.*
[start-service-reviews] [nodemon] watching extensions: js,mjs,json
[start-service-reviews] [nodemon] starting `node services/reviews/index.js`
[start-service-inventory] [nodemon] 2.0.15
[start-service-inventory] [nodemon] to restart at any time, enter `rs`
[start-service-inventory] [nodemon] watching path(s): *.*
[start-service-inventory] [nodemon] watching extensions: js,mjs,json
[start-service-inventory] [nodemon] starting `node services/inventory/index.js`
[start-service-reviews] /Users/home/@DEV/federation-demo/services/reviews/node_modules/apollo-graphql/lib/schema/buildSchemaFromSDL.js:50
[start-service-reviews]         throw new GraphQLSchemaValidationError_1.GraphQLSchemaValidationError(errors);
[start-service-reviews]         ^
[start-service-reviews] 
[start-service-reviews] GraphQLSchemaValidationError: Cannot extend type "User" because it is not defined.
[start-service-reviews] 
[start-service-reviews] Cannot extend type "Product" because it is not defined.
[start-service-reviews]     at buildSchemaFromSDL (/Users/home/@DEV/federation-demo/services/reviews/node_modules/apollo-graphql/lib/schema/buildSchemaFromSDL.js:50:15)
[start-service-reviews]     at buildSubgraphSchema (/Users/home/@DEV/federation-demo/services/reviews/node_modules/@apollo/subgraph/dist/buildSubgraphSchema.js:26:58)
[start-service-reviews]     at deprecated (internal/util.js:96:15)
[start-service-reviews]     at Object.<anonymous> (/Users/home/@DEV/federation-demo/services/reviews/index.js:50:11)
[start-service-reviews]     at Module._compile (internal/modules/cjs/loader.js:1072:14)
[start-service-reviews]     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
[start-service-reviews]     at Module.load (internal/modules/cjs/loader.js:937:32)
[start-service-reviews]     at Function.Module._load (internal/modules/cjs/loader.js:778:12)
[start-service-reviews]     at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
[start-service-reviews]     at internal/main/run_main_module.js:17:47 {
[start-service-reviews]   errors: [
[start-service-reviews]     GraphQLError: Cannot extend type "User" because it is not defined.
[start-service-reviews]         at Object.checkExtension (/Users/home/@DEV/federation-demo/services/reviews/node_modules/graphql/validation/rules/PossibleTypeExtensionsRule.js:83:9)
[start-service-reviews]         at Object.enter (/Users/home/@DEV/federation-demo/services/reviews/node_modules/graphql/language/visitor.js:303:32)
[start-service-reviews]         at visit (/Users/home/@DEV/federation-demo/services/reviews/node_modules/graphql/language/visitor.js:200:21)
[start-service-reviews]         at Object.validateSDL (/Users/home/@DEV/federation-demo/services/reviews/node_modules/graphql/validation/validate.js:121:22)
[start-service-reviews]         at buildSchemaFromSDL (/Users/home/@DEV/federation-demo/services/reviews/node_modules/apollo-graphql/lib/schema/buildSchemaFromSDL.js:48:31)
[start-service-reviews]         at buildSubgraphSchema (/Users/home/@DEV/federation-demo/services/reviews/node_modules/@apollo/subgraph/dist/buildSubgraphSchema.js:26:58)
[start-service-reviews]         at deprecated (internal/util.js:96:15)
[start-service-reviews]         at Object.<anonymous> (/Users/home/@DEV/federation-demo/services/reviews/index.js:50:11)
[start-service-reviews]         at Module._compile (internal/modules/cjs/loader.js:1072:14)
[start-service-reviews]         at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10) {
[start-service-reviews]       path: undefined,
[start-service-reviews]       locations: undefined,
[start-service-reviews]       extensions: [Object: null prototype] {}
[start-service-reviews]     },
[start-service-reviews]     GraphQLError: Cannot extend type "Product" because it is not defined.
[start-service-reviews]         at Object.checkExtension (/Users/home/@DEV/federation-demo/services/reviews/node_modules/graphql/validation/rules/PossibleTypeExtensionsRule.js:83:9)
[start-service-reviews]         at Object.enter (/Users/home/@DEV/federation-demo/services/reviews/node_modules/graphql/language/visitor.js:303:32)
[start-service-reviews]         at visit (/Users/home/@DEV/federation-demo/services/reviews/node_modules/graphql/language/visitor.js:200:21)
[start-service-reviews]         at Object.validateSDL (/Users/home/@DEV/federation-demo/services/reviews/node_modules/graphql/validation/validate.js:121:22)
[start-service-reviews]         at buildSchemaFromSDL (/Users/home/@DEV/federation-demo/services/reviews/node_modules/apollo-graphql/lib/schema/buildSchemaFromSDL.js:48:31)
[start-service-reviews]         at buildSubgraphSchema (/Users/home/@DEV/federation-demo/services/reviews/node_modules/@apollo/subgraph/dist/buildSubgraphSchema.js:26:58)
[start-service-reviews]         at deprecated (internal/util.js:96:15)
[start-service-reviews]         at Object.<anonymous> (/Users/home/@DEV/federation-demo/services/reviews/index.js:50:11)
[start-service-reviews]         at Module._compile (internal/modules/cjs/loader.js:1072:14)
[start-service-reviews]         at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10) {
[start-service-reviews]       path: undefined,
[start-service-reviews]       locations: undefined,
[start-service-reviews]       extensions: [Object: null prototype] {}
[start-service-reviews]     }
[start-service-reviews]   ]
[start-service-reviews] }
[start-service-accounts] /Users/home/@DEV/federation-demo/services/accounts/node_modules/apollo-graphql/lib/schema/buildSchemaFromSDL.js:50
[start-service-accounts]         throw new GraphQLSchemaValidationError_1.GraphQLSchemaValidationError(errors);
[start-service-accounts]         ^
[start-service-accounts] 
[start-service-accounts] GraphQLSchemaValidationError: Cannot extend type "Query" because it is not defined. Did you mean "User"?
[start-service-accounts]     at buildSchemaFromSDL (/Users/home/@DEV/federation-demo/services/accounts/node_modules/apollo-graphql/lib/schema/buildSchemaFromSDL.js:50:15)
[start-service-accounts]     at buildSubgraphSchema (/Users/home/@DEV/federation-demo/services/accounts/node_modules/@apollo/subgraph/dist/buildSubgraphSchema.js:26:58)
[start-service-accounts]     at deprecated (internal/util.js:96:15)
[start-service-accounts]     at Object.<anonymous> (/Users/home/@DEV/federation-demo/services/accounts/index.js:30:11)
[start-service-accounts]     at Module._compile (internal/modules/cjs/loader.js:1072:14)
[start-service-accounts]     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
[start-service-accounts]     at Module.load (internal/modules/cjs/loader.js:937:32)
[start-service-accounts]     at Function.Module._load (internal/modules/cjs/loader.js:778:12)
[start-service-accounts]     at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
[start-service-accounts]     at internal/main/run_main_module.js:17:47 {
[start-service-accounts]   errors: [
[start-service-accounts]     GraphQLError: Cannot extend type "Query" because it is not defined. Did you mean "User"?
[start-service-accounts]         at Object.checkExtension (/Users/home/@DEV/federation-demo/services/accounts/node_modules/graphql/validation/rules/PossibleTypeExtensionsRule.js:83:9)
[start-service-accounts]         at Object.enter (/Users/home/@DEV/federation-demo/services/accounts/node_modules/graphql/language/visitor.js:303:32)
[start-service-accounts]         at visit (/Users/home/@DEV/federation-demo/services/accounts/node_modules/graphql/language/visitor.js:200:21)
[start-service-accounts]         at Object.validateSDL (/Users/home/@DEV/federation-demo/services/accounts/node_modules/graphql/validation/validate.js:121:22)
[start-service-accounts]         at buildSchemaFromSDL (/Users/home/@DEV/federation-demo/services/accounts/node_modules/apollo-graphql/lib/schema/buildSchemaFromSDL.js:48:31)
[start-service-accounts]         at buildSubgraphSchema (/Users/home/@DEV/federation-demo/services/accounts/node_modules/@apollo/subgraph/dist/buildSubgraphSchema.js:26:58)
[start-service-accounts]         at deprecated (internal/util.js:96:15)
[start-service-accounts]         at Object.<anonymous> (/Users/home/@DEV/federation-demo/services/accounts/index.js:30:11)
[start-service-accounts]         at Module._compile (internal/modules/cjs/loader.js:1072:14)
[start-service-accounts]         at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10) {
[start-service-accounts]       path: undefined,
[start-service-accounts]       locations: undefined,
[start-service-accounts]       extensions: [Object: null prototype] {}
[start-service-accounts]     }
[start-service-accounts]   ]
[start-service-accounts] }
[start-service-reviews] [nodemon] app crashed - waiting for file changes before starting...
[start-service-products] /Users/home/@DEV/federation-demo/services/products/node_modules/apollo-graphql/lib/schema/buildSchemaFromSDL.js:50
[start-service-products]         throw new GraphQLSchemaValidationError_1.GraphQLSchemaValidationError(errors);
[start-service-products]         ^
[start-service-products] 
[start-service-products] GraphQLSchemaValidationError: Cannot extend type "Query" because it is not defined.
[start-service-products]     at buildSchemaFromSDL (/Users/home/@DEV/federation-demo/services/products/node_modules/apollo-graphql/lib/schema/buildSchemaFromSDL.js:50:15)
[start-service-products]     at buildSubgraphSchema (/Users/home/@DEV/federation-demo/services/products/node_modules/@apollo/subgraph/dist/buildSubgraphSchema.js:26:58)
[start-service-products]     at deprecated (internal/util.js:96:15)
[start-service-products]     at Object.<anonymous> (/Users/home/@DEV/federation-demo/services/products/index.js:31:11)
[start-service-products]     at Module._compile (internal/modules/cjs/loader.js:1072:14)
[start-service-products]     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
[start-service-products]     at Module.load (internal/modules/cjs/loader.js:937:32)
[start-service-products]     at Function.Module._load (internal/modules/cjs/loader.js:778:12)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
[start-service-products]     at internal/main/run_main_module.js:17:47 {
[start-service-products]   errors: [
[start-service-products]     GraphQLError: Cannot extend type "Query" because it is not defined.
[start-service-products]         at Object.checkExtension (/Users/home/@DEV/federation-demo/services/products/node_modules/graphql/validation/rules/PossibleTypeExtensionsRule.js:83:9)
[start-service-products]         at Object.enter (/Users/home/@DEV/federation-demo/services/products/node_modules/graphql/language/visitor.js:303:32)
[start-service-products]         at visit (/Users/home/@DEV/federation-demo/services/products/node_modules/graphql/language/visitor.js:200:21)
[start-service-products]         at Object.validateSDL (/Users/home/@DEV/federation-demo/services/products/node_modules/graphql/validation/validate.js:121:22)
[start-service-products]         at buildSchemaFromSDL (/Users/home/@DEV/federation-demo/services/products/node_modules/apollo-graphql/lib/schema/buildSchemaFromSDL.js:48:31)
[start-service-products]         at buildSubgraphSchema (/Users/home/@DEV/federation-demo/services/products/node_modules/@apollo/subgraph/dist/buildSubgraphSchema.js:26:58)
[start-service-products]         at deprecated (internal/util.js:96:15)
[start-service-products]         at Object.<anonymous> (/Users/home/@DEV/federation-demo/services/products/index.js:31:11)
[start-service-products]         at Module._compile (internal/modules/cjs/loader.js:1072:14)
[start-service-products]         at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10) {
[start-service-products]       path: undefined,
[start-service-products]       locations: undefined,
[start-service-products]       extensions: [Object: null prototype] {}
[start-service-products]     }
[start-service-products]   ]
[start-service-products] }
[start-service-accounts] [nodemon] app crashed - waiting for file changes before starting...
[start-service-products] [nodemon] app crashed - waiting for file changes before starting...
[start-service-inventory] /Users/home/@DEV/federation-demo/services/inventory/node_modules/apollo-graphql/lib/schema/buildSchemaFromSDL.js:50
[start-service-inventory]         throw new GraphQLSchemaValidationError_1.GraphQLSchemaValidationError(errors);
[start-service-inventory]         ^
[start-service-inventory] 
[start-service-inventory] GraphQLSchemaValidationError: Cannot extend type "Product" because it is not defined.
[start-service-inventory]     at buildSchemaFromSDL (/Users/home/@DEV/federation-demo/services/inventory/node_modules/apollo-graphql/lib/schema/buildSchemaFromSDL.js:50:15)
[start-service-inventory]     at buildSubgraphSchema (/Users/home/@DEV/federation-demo/services/inventory/node_modules/@apollo/subgraph/dist/buildSubgraphSchema.js:26:58)
[start-service-inventory]     at deprecated (internal/util.js:96:15)
[start-service-inventory]     at Object.<anonymous> (/Users/home/@DEV/federation-demo/services/inventory/index.js:32:11)
[start-service-inventory]     at Module._compile (internal/modules/cjs/loader.js:1072:14)
[start-service-inventory]     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
[start-service-inventory]     at Module.load (internal/modules/cjs/loader.js:937:32)
[start-service-inventory]     at Function.Module._load (internal/modules/cjs/loader.js:778:12)
[start-service-inventory]     at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
[start-service-inventory]     at internal/main/run_main_module.js:17:47 {
[start-service-inventory]   errors: [
[start-service-inventory]     GraphQLError: Cannot extend type "Product" because it is not defined.
[start-service-inventory]         at Object.checkExtension (/Users/home/@DEV/federation-demo/services/inventory/node_modules/graphql/validation/rules/PossibleTypeExtensionsRule.js:83:9)
[start-service-inventory]         at Object.enter (/Users/home/@DEV/federation-demo/services/inventory/node_modules/graphql/language/visitor.js:303:32)
[start-service-inventory]         at visit (/Users/home/@DEV/federation-demo/services/inventory/node_modules/graphql/language/visitor.js:200:21)
[start-service-inventory]         at Object.validateSDL (/Users/home/@DEV/federation-demo/services/inventory/node_modules/graphql/validation/validate.js:121:22)
[start-service-inventory]         at buildSchemaFromSDL (/Users/home/@DEV/federation-demo/services/inventory/node_modules/apollo-graphql/lib/schema/buildSchemaFromSDL.js:48:31)
[start-service-inventory]         at buildSubgraphSchema (/Users/home/@DEV/federation-demo/services/inventory/node_modules/@apollo/subgraph/dist/buildSubgraphSchema.js:26:58)
[start-service-inventory]         at deprecated (internal/util.js:96:15)
[start-service-inventory]         at Object.<anonymous> (/Users/home/@DEV/federation-demo/services/inventory/index.js:32:11)
[start-service-inventory]         at Module._compile (internal/modules/cjs/loader.js:1072:14)
[start-service-inventory]         at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10) {
[start-service-inventory]       path: undefined,
[start-service-inventory]       locations: undefined,
[start-service-inventory]       extensions: [Object: null prototype] {}
[start-service-inventory]     }
[start-service-inventory]   ]
[start-service-inventory] }
[start-service-inventory] [nodemon] app crashed - waiting for file changes before starting...
^C[start-service-accounts] npm run start-service-accounts exited with code 0
[start-service-inventory] npm run start-service-inventory exited with code 0
[start-service-reviews] npm run start-service-reviews exited with code 0
[start-service-products] npm run start-service-products exited with code 0
Maxwell2022 commented 2 years ago

extend type .... is not working (anymore?) you need to use the @extends directive. This is really badly documented.

extend type User @key(fields: "id") {
    id: ID! @external
    username: String @external
    reviews: [Review]
  }

becomes

type User @extend @key(fields: "id") {
    id: ID! @external
    username: String @external
    reviews: [Review]
  }

it looks like extend is a reserved keyword to extend type from the same schema definition file

Maxwell2022 commented 2 years ago

@peggyrayzis (sorry for the tagging, but your role at Apollo says "developer experience") is there any one in charge of maintaining the demo repositories with latest version of the server?

Also the Apollo documentation is mentioning this same extend type .... everywhere. Only in the specs they mentioned this directive

patrickdronk commented 2 years ago

It is actually @extends for anyone trying out @extend and it's not working.

hiderer commented 2 years ago

@extends works fine! This information saved my life.

kyle-banner commented 2 years ago

For anyone that doesn't want to change the code use the below versions in the parent-level package.json:

  "dependencies": {
    "@apollo/gateway": "^0.28.1",
    "apollo-server": "^2.24.1",
    "graphql": "^15.5.0"
  }

and the below in each of the services' package.json:

  "dependencies": {
    "@apollo/federation": "^0.25.0",
    "apollo-server": "^2.24.1",
    "graphql": "^15.5.0"
  }

I'm assuming the above errors are thrown because the package.jsons are using "latest" when they should be locked down to v1 when this demo was written. Federation v2 was just released and I'm assuming these package.jsons are pulling down v2. My versions aren't the latest for v1 but will at least make their code functional.