graphql-testx icon indicating copy to clipboard operation
graphql-testx copied to clipboard

Add the option to load the type model definition from file

Open b1zzu opened this issue 5 years ago • 8 comments

It would be nice if it could be possible to do something like this:

new TestxServer(path.resolve(__dirname, 'schema.graphql'))

but because both the model definition and the file path are strings, in my opinion, something like this is more clear:

new TestxServer({file: path.resolve(__dirname, 'schema.graphql')})

or we could expose a helper method:

testxServerFromFile(path.resolve(__dirname, 'schema.graphql'))

b1zzu avatar Dec 04 '19 16:12 b1zzu

@b1zzu I really like this feature, we can try to do something like constructor overload.

vinifarias avatar Dec 05 '19 02:12 vinifarias

Blocked by: https://github.com/aerogear/graphql-testx/issues/103

b1zzu avatar Dec 05 '19 12:12 b1zzu

@vinifarias I've opened a separate issue to discuss how we could improve the TestxServer constructor/api, we can move the discussion there. Btw what's a constructor overload?

b1zzu avatar Dec 05 '19 12:12 b1zzu

@b1zzu It's when you use multiple constructors for a class, and each of them has different parameters.

vinifarias avatar Dec 05 '19 14:12 vinifarias

@vinifarias that's not possible in typescript/javascript, the alternative in our case would be to add n optional parameters, but it has this drawback

new TestxServer("option one", undefined, undefined, undefined, undefined, "som other options")

b1zzu avatar Dec 05 '19 14:12 b1zzu

@b1zzu Sorry XD, it's not a good idea to keep this type of constructor with many optional parameters.

vinifarias avatar Dec 05 '19 14:12 vinifarias

@vinifarias no need to be sorry :smile:, in Java it's a good approach because it's possible to define multiple constructors with the same number of arguments

b1zzu avatar Dec 05 '19 14:12 b1zzu

I plan to use testx with graphback that will use graphql-config.

GraphQL Config always passing compiled schema/string. Files are hard as all depends on the __dirname and process.cwd

wtrocki avatar Jan 28 '20 12:01 wtrocki