1

I'm attempting to create a microservice based application that uses two remote Prisma/GraphQL schemas that run in Docker and a gateway that introspects them using schema stitching.

Prisma/GraphQL Schemas:

// Profile Schema service - http:localhost:3000/profile
type Profile {
  id: ID!
  user_id: ID!
  firstName: String!
  ...
}

type Query {
  findProfileById(id: ID!): Profile
  findProfileByUserID(user_id: ID!): Profile
}

// User Schema service - http:localhost:5000/user
type User {
  id: ID!
  profileID: ID!
  email: String!
  ...
}

type Query {
  findUserById(id: ID!): User
  findUserByProfileID(profileID: ID!): Profile
}

Now in the Gateway server I am able to introspect and mergeSchemas using graphql-tools successfully and I have added extended types to allow for relationships between the two types

// LinkTypeDefs
extend type Profile {
    user: User
}

extend type User {
   userProfile: Profile
}

I followed Apollo GraphQL documentation for schema stitching with remote schemas and this is the resolver I have for the now merged schemas

        app.use('/gateway', bodyParser.json(), graphqlExpress({ schema: mergeSchemas({ 
        schemas: [
            profileSchema,
            userSchema,
            linkTypeDefs
        ], 
        resolvers: mergeInfo =>  ({
            User: {
                userProfile: {
                    fragment: `fragment UserFragment on User { id }`,
                    resolve(user, args, context, info) {
                        return delegateToSchema({
                            schema: profileSchema,
                            operation: 'query',
                            fieldName: 'findProfileByUserId',
                            args: {
                                user_id: user.id
                            },
                            context,
                            info
                        },

                        );
                    },
                },
            },
            Profile: {
                user: {
                    fragment: `fragment ProfileFragment on Profile { id }`,
                    resolve(profile, args, context, info) {
                        return delegateToSchema({
                            schema: authSchema,
                            operation: 'query',
                            fieldName: 'findUserByProfileId',
                            args: {
                                profileID: profile.id
                            },
                            context,
                            info

                        })
                    }
                }
            }
        }),
    })
}));

The issue I am having is everytime I query User or Profile for their new extended fields it always returns null. I have made sure that I have created User object with an existing profileId, likewise with Profile object with an existing userId. This is a sample of the query results

enter image description here

I have gone through the docs for about a week now and nothing seems to be working. From my undertstanding everything is plugged in properly. Hopefully someone can help. I have a feeling it has something to do with the fragments. I can provide a screenshot of the user and profile objects for more clarification if need be. Thanks.

remedy
  • 125
  • 1
  • 9
  • In your resolvers, specifically for the user field, you have `profile` as the first param. Are you sure it has any content at all? GraphQL only processes fields if the root content is not null. So perhaps it's not even processing the resolver for this field and therefore it's not delegating the schema. – bazaglia Jul 20 '18 at 08:38

1 Answers1

0

I ended up resolving the issue by changing delegateToSchema() to info.mergeInfo.delegate(). That seemed to do the trick.

enter image description here

I have not tried the newly updated info.mergeInfo.delegateToSchema yet. Will update this post if the updated version works but for now this does the job for me.

Hopefully this can help someone in the future!

remedy
  • 125
  • 1
  • 9