jcward / haxe-graphql

Utilities for working with Haxe and GraphQL.
MIT License
23 stars 6 forks source link

Block String issue #37

Closed darmie closed 5 years ago

darmie commented 5 years ago

https://github.com/jcward/haxe-graphql/blob/986944f6e5698fb251180ceace4457ee550e940d/proj/parser/src/graphql/parser/GeneratedLexer.hx#L514

What if you detect BlockString by regex and then remove it before generating the source?

class Test {
    static function main() {
        var r = ~/("""(\w+|(\w+\s+))""")|("""[\r\n]+\w+[\r\n]+""")/ig;
        var buf = new StringBuf();
        buf.add('"""hello"""');
        buf.add("\n");
        buf.add('"""');
        buf.add("\n");
        buf.add("boxies");
        buf.add("\n");
        buf.add('"""');

        var str = buf.toString();

        trace(r.match(str));

        var output = r.map(str, function(rx){
          trace(rx.matched(0));
          return "";  
        });
        trace(output);
    }
}

See Try Haxe!

jcward commented 5 years ago

{ throw 'TODO: implement blockStringValue(rawValue)'; null; });

image

Lol, thanks for reminding me to look into this.

Interesting, BlockString is not in the Oct2016 spec, but it is in the June2018 spec. Nevertheless, it is in the 0.13.2 lexer.js that I'm sourcing from.

darmie commented 5 years ago

I am trying to work on a haxe template for Prisma. And your generator will come in handy.

This block string and Union seems like the only blocker

jcward commented 5 years ago

Thanks for the PR / #38 ! I've update the generators to import graphql-js v14.3.0 javascript, and made a couple fixes to the BlockStringUtil.hx (per a new block string testcase).

I've re-deployed the web demo, you can play with block strings (and see their values, with leading spaces removed, in the document tree):

Screenshot from 2019-05-08 11-01-46

Sample gql:

type TestBlockString {
  foo(something:String!="""

   hello
   asdf

"""): String
}

Let me know if this all works for what you're doing! Cheers!

darmie commented 5 years ago

Awesome!!