Exemplo n.º 1
0
        public void SuccessfullyValidatesEmptyGqlx()
        {
            var compiler = new GqlxCompiler();
            var result   = compiler.Validate(@"");

            Assert.AreEqual(false, result);
        }
Exemplo n.º 2
0
        public void SuccessfullyValidatesCorrectComplexGqlx()
        {
            var compiler = new GqlxCompiler();
            var result   = compiler.Validate(@"
  type Foo {
    id: ID
    name: String
  }

  type Bar {
    id: ID
    age: Int
  }

  type Query {
    foo: [Foo]

    bar(name: String): Bar {
      get('api')
        .map(x => x[name].map(y => y.element))
        .filter(x => !x)
        .map(x => `Hello there ${x.y} from ${name}`)
    }

    qxz(id: ID!, name: String, ages: [Int]): [Bar] {
      get('api')
    }

    items(hashes: [String]): [Foo] {
      (hashes && hashes.length) ?
        post('api/item', {
          hashes,
          content: '',
        }).items
      :
        get('api/item').items
    }
  }

  type Mutation {
    foo(a: String, b: Float): [Int] {
      post('api/foo', {
        body: get('api'),
      })
    }
  }

  type Subscription {
    foo: [Foo] {
      listen('foo')
    }
  }
");

            Assert.AreEqual(true, result);
        }
Exemplo n.º 3
0
        public void SuccessfullyValidatesIncorrectGqlx()
        {
            var compiler = new GqlxCompiler();

            Assert.Throws <JavaScriptException>(() => compiler.Validate(@"
  type Mutation {
    foo(id: ID): [Int] {
      post('api/foo/' + ib, {
        body: get('api'),
      })
    }
  }
"));
        }
Exemplo n.º 4
0
        public void SuccessfullyCompilesSimpleGqlx()
        {
            var compiler = new GqlxCompiler();
            var result   = compiler.Compile("test", @"
  type Foo {
    id: ID
    name: String
  }

  type Query {
    foo: [Foo] {
      get('api/foo')
    }
  }
");

            Assert.AreEqual("test", result.Name);
        }
Exemplo n.º 5
0
        public void SuccessfullyValidatesCorrectSimpleGqlx()
        {
            var compiler = new GqlxCompiler();
            var result   = compiler.Validate(@"
  type Foo {
    id: ID
    name: String
  }

  type Bar {
    id: ID
    age: Int
  }

  type Query {
    foo: [Foo] {
      get('api/foo')
    }
  }
");

            Assert.AreEqual(true, result);
        }