question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use computation expressions for defining schema

See original GitHub issue

We talked with @johnberzy-bazinga about idea of using cexprs for defining schemas, i.e instead of current:

let Person = Define.Object("Person", "description", [
    Define.Field("firstName", String, "Person's first name", fun ctx p -> p.FirstName)
    Define.Field("lastName", String, "Person's last name", fun ctx p -> p.LastName)
])

have something like:

let Person = outputObject "Person" {
    description "description"
    field "firstName" String "Person's first name" [] (fun _ p -> p.FirstName)
    field "lastName" String "Person's last name" [] (fun _ p -> p.LastName)
}

This topic is to discuss about that. Is it even possible? Is it feasible?

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
Horusiathcommented, May 12, 2017

@Lenne231 there are several issues with following graphql-js desing:

  1. You’re basically defining schema twice (first time as string, second as object with resolver methods). While this may be solution for javascript - because there’s no way to annotate GraphQL type system there - it looks counterproductive in typed languages.
  2. Since it’s a string-based definition, you loose all of the power given you by the IDE. No syntax highlighting, no autocompletion. Even trivial things, like checking if you correctly closed all opened scopes and there’s no brace missing, must be done by you. Type provider may validate that string, but it won’t show you where in your string the bug is hidden.
  3. In case of typos in type names or identifiers, there’s no way to guarantee that Type Provider will behave correctly. In optimistic case it won’t compile, as under the typo it will find, that GraphQL schema is not total, and there are some not-described types. But again no help from the complier or IDE side there. In pessimistic case it will swallow that, and throw an error at runtime, when you’ll try to call misspelled field.
0reactions
Swoorupcommented, Oct 7, 2019

Have to add that consuming the API in this form: https://github.com/GT-CHaRM/CHaRM.Backend/blob/master/src/CHaRM.Backend/Schema/Item.fs

makes it much more simpler and easier to implement than the current form.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Computation expressions: Introduction
Computation expressions seem to have a reputation for being abstruse and difficult to understand. On one hand, they're easy enough to use.
Read more >
Computation Expressions - F# | Microsoft Learn
You can define the characteristics of your own computation expressions by creating a builder class and defining certain special methods on the ...
Read more >
F Sharp Programming/Computation Expressions
Defining Computation Expressions. Computation expressions are fundamentally the same concept as seen above, although they hide the complexity of monadic syntax ...
Read more >
Computation Expressions Explained | Step-By-Step Tutorial
... Timestamps: 0:00 Intro 0:10 What are computation expressions 4:10 Tutorial 4:50 Bare minimum definition 6:25 return method 8:32 let ...
Read more >
Custom Keywords in Computation Expressions
Computation expressions can be very useful for creating a highly readable, imperative-style chain of instructions. If you design the CE well ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found