hasura / graphql-engine

Blazing fast, instant realtime GraphQL APIs on your DB with fine grained access control, also trigger webhooks on database events.
https://hasura.io
Apache License 2.0
31.17k stars 2.77k forks source link

Unable to add second remote schema containing same type #5567

Open mathiasschopmans opened 4 years ago

mathiasschopmans commented 4 years ago

For my current project I want to add two remote services, both using Apollo-Server. When I try to add the second service Hasura complains about a schema mismatch.

[
    {
        "definition": {
            "definition": {
                "timeout_seconds": 15,
                "headers": [],
                "url_from_env": "SEARCH_SERVICE_ENDPOINT",
                "forward_client_headers": false
            },
            "name": "search-service",
            "comment": null
        },
        "reason": "types: [ CacheControlScope ] have mismatch with current graphql schema. HINT: Types must be same.",
        "type": "remote_schema"
    }
]

It seems that Apollo is adding a internal CacheControlScope-Type, but I can ensure, that they both have the same definition:

enum CacheControlScope {
  PUBLIC
  PRIVATE
}

Is this behaviour intended?

Maybe related to #5046

mathiasschopmans commented 4 years ago

Basic Apollo Setup:

package.json

{
  "name": "panther-search-service",
  "version": "1.0.0",
  "main": "index.js",
  "author": "AOE <developer@aoe.com>",
  "license": "MIT",
  "private": true,
  "scripts": {
    "start": "node index.js",
    "dev": "node -r dotenv/config index.js",
    "test": "jest"
  },
  "dependencies": {
    "apollo-server": "^2.16.1",
    "graphql": "^15.3.0",
  }
}

server.js

const { ApolloServer, gql } = require('apollo-server');

// The GraphQL schema
const typeDefs = gql`
    type Query {
        "A simple type for getting started!"
        hello: String
    }
`;

// A map of functions which return data for the schema.
const resolvers = {
  Query: {
    hello: () => 'world',
  },
};

const server = new ApolloServer({
  typeDefs,
  resolvers,
});

server.listen().then(({ url }) => {
  console.log(`🚀 Server ready at ${url}`);
});

node server.js

mathiasschopmans commented 4 years ago

I found a workaround to ignore the creation of CacheControlScope enum type. When initializing Apollo with a schema instead of typeDefs and resolvers, it won't add it.

const { ApolloServer, gql, makeExecutableSchema } = require('apollo-server');

// The GraphQL schema
const typeDefs = gql`
    type Query {
        "A simple type for getting started!"
        hello: String
    }
`;

// A map of functions which return data for the schema.
const resolvers = {
  Query: {
    hello: () => 'world',
  },
};

const executableSchema = makeExecutableSchema({
  typeDefs,
  resolvers,
});

const server = new ApolloServer({
  schema: executableSchema,
  introspection: true,
});

server.listen().then(({ url }) => {
  console.log(`🚀 Server ready at ${url}`);
});

The issue is still valid and seems to be related to https://github.com/hasura/graphql-engine/pull/4821

danharsanyi commented 3 years ago

@mathiasschopmans I had the exact same issue with my Remote Schema endpoints after bumping apollo-server-cloud-functions and graphql versions to the latest ones and was able to fix it by first reloading my metadata under the Hasura Metadata Actions section. Just ticked "Reload all remote schemas" and then clicked "Reload", and then I was able to reload each schema individually. Hope that helps!

Screen Shot 2021-01-04 at 3 09 18 pm

evandro-prontocombustiveis commented 3 years ago

I fixed it adding a suffix /v1/graphql to the Remote Schema URL.

Like this:

File: remote_schemas.yaml

- name: YourRemoteSchema
  definition:
    url: https://yourHasuraApi/v1/graphql
    timeout_seconds: 60
    headers:
      - name: x-hasura-admin-secret
        value: "yourSecretHere"