0

I've got a bunch of graphQL fragments set up in my React/Apollo app, but I really need to access them on my Node server.

For example, in my client I'm attempting to do this query, to get all relevant Person and Company entities:

query GET_REPORTING_CLIENTS{
    reportingClients{
        people {
            ...PersonFragment
        }
        companies {
            ...CompanyFragment
        }
    }
}

Now, I can't just pass info into the queries on my server, cause context.db.query.person obviously won't have a key for 'people'.

Ideally, I'd be able to go:

context.db.query.person({
     where: (query details)
}, PersonFragment)

...but that doesn't work cause the server doesn't have the fragment. At the moment I'm getting around that by copy-pasting huge blocks of graphQL from the client to the app, but it's a really poor solution.

Is there an answer, or does everything just need to double up?

MitchEff
  • 1,417
  • 14
  • 29

1 Answers1

0

I recommend using yarn workspaces, especially if you plan to make a mobile app. You can package chunks of code where it can be shared between the frontend and backend applications.

https://yarnpkg.com/en/docs/workspaces

wrod7
  • 179
  • 10