Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import syntax in schema #6

Closed
vektah opened this issue Feb 14, 2018 · 13 comments
Closed

import syntax in schema #6

vektah opened this issue Feb 14, 2018 · 13 comments
Labels
enhancement New feature or request parser Blocked on parser stale

Comments

@vektah
Copy link
Collaborator

vektah commented Feb 14, 2018

Follow the conventions in https://github.com/graphcool/graphql-import to stitch together multiple schemas.

Prereq for Schema Stitching

@vektah vektah added this to the 1.0 milestone Feb 14, 2018
@vektah vektah added the enhancement New feature or request label Mar 8, 2018
@vektah vektah added the parser Blocked on parser label May 3, 2018
@vektah vektah added this to To do in 1.0 Release Jun 29, 2018
@vektah vektah removed this from the 1.0 milestone Jun 29, 2018
@vektah vektah removed this from Features in 1.0 Release Jul 14, 2018
@piotrkochan
Copy link

this is a must!

@codyleyhan
Copy link
Contributor

Is there potential of doing an even easier solution by just having the user supply a list of files related to the schema in the config file ie:

schema.graphql

type Schema {
   getUser(id: Int) User
}

user.graphql

type User {
 ...
}

gengql.yml

...
schema_files:
    - "schema.graphql"
    - "user.graphql"
...

Which could then be read in and parsed/validated at the same time using the parser? This seems to be pretty easy to implement if it is a good alternative solution

@piotrkochan
Copy link

piotrkochan commented Sep 7, 2018 via email

@rolimb
Copy link

rolimb commented Sep 19, 2018

Personally, I use simple bash script for it.

./scripts/genSchema.sh

#!/bin/sh
find ../schema -type f -name '*.gql' | xargs -I{} sh -c "cat {}; echo ''" > ../schema/schema_gen.graphql

It simply concatenates all *.gql files under ../schema into single ../schema/schema_gen.graphql file.

Then I just added go:generate above gqlgen:

//go:generate sh ../scripts/genSchema.sh
//go:generate gorunpkg github.com/99designs/gqlgen

Does the job.

@piotrkochan
Copy link

Hey @rolimb, you said:

Then I just added go:generate above gqlgen:

Could you clarify where exactly you've added that snippet?

@blasterpistol
Copy link

@rolimb can be simplified
for f in ./gql-schema/*.gql; do cat $f; echo; done > ./schema.gql

@rolimb
Copy link

rolimb commented Sep 21, 2018

@piotrkochan, Not sure about your question. Actually I took your advise:

You can write bash or bat script to concatenate these files before gqlgen

And that's exactly what I did.
Anyway, my resolver.go file looks like this:

// Package graph ...
//go:generate sh ../scripts/genSchema.sh
//go:generate gorunpkg github.com/99designs/gqlgen
package graph

// Resolver ...
type Resolver struct {
	Server *Server
}

// RootMutation resolver
func (r Resolver) RootMutation() RootMutationResolver {
	return r.Server
}

// RootQuery resolver
func (r Resolver) RootQuery() RootQueryResolver {
	return r.Server
}

@rolimb
Copy link

rolimb commented Sep 21, 2018

@DenisNeustroev, I'm sure it can be simplified and/or done in other million different ways.
But I have to disagree. Yours is limited to a single directory, but I needed to go down the directory tree and pluck all the gql files.

@piotrkochan
Copy link

I mean, I haven't seen golang syntax like:

// Package graph ...
//go:generate sh ../scripts/genSchema.sh
//go:generate gorunpkg github.com/99designs/gqlgen

Does it really run these scripts automatically?

@rolimb
Copy link

rolimb commented Sep 23, 2018

@piotrkochan, I followed the instructions from Finishing touches.
But to make sure it does work, I just deleted all generated files, ran:

go generate ./...

in the project's root and the files got regenerated:

  • schema_gen.graphql by 1st statement
  • generated.go & models_gen.go by 2nd.

@andrewmunro
Copy link

@vektah Is there any updates on this? Looking at the parser this should be possible now? I might have a go at making a PR...

@rodcorsi
Copy link

The graphql-import has capability to import one specific element and his dependencies. I think this resource is very useful.

# import createTodo from "schemas.graphql"

Maybe we can reach the same capability in gqlgen.yml

schema:
  - "{createTodo} from schemas.graphql"

@stale
Copy link

stale bot commented Aug 28, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Aug 28, 2019
@stale stale bot closed this as completed Sep 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request parser Blocked on parser stale
Projects
None yet
Development

No branches or pull requests

7 participants