Skip to content
This repository was archived by the owner on Sep 3, 2021. It is now read-only.

Feature request: makeAugmentedSchema and Apollo's buildFederatedSchema integration support #260

Closed
emregency opened this issue Jun 3, 2019 · 13 comments

Comments

@emregency
Copy link

Typically,

Types may have different attributes that are requiring other dB/service access than neo4j i.e. profile photos for User where the link is stored in neo4j db and the image itself somewhere else (a recommended practice by neo4j). In such cases, stitching schemas to different services is required but is quite painful.

The new release of Apollo Federation provides a very convenient way to manage these multi service API design.

However,

The implementation requires the developer to augment the schema with a new method called buildFederatedSchema where new directives for managing easily the interdependence among schemas are introduced :

const server = new ApolloServer({
  schema: buildFederatedSchema([{ typeDefs, resolvers }])
});

as illustrated here.

Is it possible to concatenate or provide an elegant way of enabling makeAugmentedSchema and buildFederatedSchema ?

@johnymontana
Copy link
Contributor

Yes, this is definitely something we'll need to look into. I have it on my list to research.

@Pruxis
Copy link
Contributor

Pruxis commented Jul 3, 2019

Hey @emregency I got this working but without the generated queries and mutations (which is our desired use case)

You can just import the directives like this

import { cypherDirective, relationDirective } from 'neo4j-graphql-js/dist/utils';

const server = new ApolloServer({
  schema, // This is your federated schema.
  schemaDirectives: [{ cypher: cypherDirective, relation: relationDirective }],
  context: (): Context => ({ driver }),
  playground: true,
  introspection: true,
});

// Sample resolvers
import { neo4jgraphql } from 'neo4j-graphql-js';
const resolvers = {
  Query: { test: neo4jgraphql }
}

@emregency
Copy link
Author

emregency commented Jul 6, 2019 via email

@emregency
Copy link
Author

emregency commented Jul 6, 2019 via email

@Pruxis
Copy link
Contributor

Pruxis commented Jul 31, 2019

@emregency also check #283

@wheresrhys
Copy link

wheresrhys commented Aug 28, 2019

I'm interested, after the last PR, what the remaining clashes are between makeAugmentedSchema and buildFederatedSchema are? e.g. does it clash with one of mutations, filters, ordering specifically, or is it to do with something more fundamental in how makeAugmatedSchema works

@maiieul
Copy link

maiieul commented Sep 25, 2019

Hi @Pruxis, thanks for posting your solution. I tried it but couldn't make it work with buildFederatedSchema. I keep getting these errors:
errorsGraphQLSchemaValidationError: Unknown directive "cypher". errorsGraphQLSchemaValidationError: Unknown directive "relation".

But it works perfectly fine if I remove all the @cypher and @relation directives.

Here's my code:

const server = new ApolloServer({
  schema: buildFederatedSchema([{
    typeDefs,
    resolvers,
  }]),
  schemaDirectives: { cypher: cypherDirective, relation: relationDirective },
  context: ({req}) => { 
    return {
      headers: req.headers,
      driver }},
  introspection: true,
  playground: true,
});`
```

Any help is more than welcome :)

@maiieul
Copy link

maiieul commented Sep 26, 2019

Okay, the problem was coming from the schema itself. Just adding the directives that I found in the generated schema of makeAugmentedSchema to the schema and it works.

directive @cypher(statement: String) on FIELD_DEFINITION
directive @relation(
  name: String
  direction: _RelationDirections
  from: String
  to: String
) on FIELD_DEFINITION | OBJECT
directive @additionalLabels(labels: [String]) on OBJECT
directive @MutationMeta(
  relationship: String
  from: String
  to: String
) on FIELD_DEFINITION
directive @neo4j_ignore on FIELD_DEFINITION
directive @isAuthenticated on OBJECT | FIELD_DEFINITION
directive @hasRole(roles: [Role]) on OBJECT | FIELD_DEFINITION

enum _RelationDirections {
  IN
  OUT
}

@bwalsh
Copy link

bwalsh commented Feb 15, 2020

Hell all. Newbie question. Just started experimenting with grandstack + apollo federation. Is there a canonical example on how this should work?

@davidLeonardi
Copy link

I second @bwalsh 's request. Could someone please point towards documentation on how this can be used? It's quite unclear at the moment.

My usecase is that i need federation because one graphql service handles some domain business logic, and the neo4j data is handled by a separate service.

Thanks :)

@agnewp
Copy link

agnewp commented May 7, 2020

i would love to be able to use the augmented schema with Apollo federation. without federation support, i can only (barely/awkwardly) use your directives. :(

@michaeldgraham
Copy link
Collaborator

Hi everyone! We recently updated with support for using Apollo Federation & Gateway. You can check out a guide added to the documentation here. I didn't notice to reference this issue in the recent PR, but it is now. :)

@bwalsh
Copy link

bwalsh commented May 18, 2020

Thanks very much. Looking forward to trying this soon.

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

No branches or pull requests

9 participants